How to Remove Empty or Null Values from JSON using JQuery?

By Hardik Savani July 4, 2023 Category : jQuery

If you want to remove all empty values from javascript json object then i will show you how to remove null and empty values from json object variable. we can easily delete null values from json object in jquery.

here bellow i give you simple example to remove all null values in jquery json object. i just created one simple html file so, you can understand to remove all null values in javascript. Just see example:


<!DOCTYPE html>



<title>How to remove empty and null values from json object in jquery? -</title>

<script src=""></script>



<script type="text/javascript">

const myObj = {

b:'my object',

c: '',

d: null,

f: {v: 1, x: '', y: null, m: {a:'asd'}}


const removeEmptyOrNull = (obj) => {

Object.keys(obj).forEach(k =>

(obj[k] && typeof obj[k] === 'object') && removeEmptyOrNull(obj[k]) ||

(!obj[k] && obj[k] !== undefined) && delete obj[k]


return obj;


myObj2 = removeEmptyOrNull(myObj);





I hope it can help you ....