var obj = { a: 1, b: null, c: undefined }; print(JSON.stringify(obj, function(k, v){ return typeof v === 'undefined' ? null : v; }));