Skip to content Skip to sidebar Skip to footer

Json.stringify Filter For Properties With Object Values Is Not Working

Can someone please clarify the rule of filtering? property z is not being stringified properly, see last line pls. MDN says 'if an array, specifies the set of properties included i

Solution 1:

From MDN, if replacer(the second parameter of JSON.stringify) is an array it specifies the set of properties included in objects in the final string.

You set it as ["x","y","z"] in which case your resulting string has those three properties, what you may have missed is that it is applies to all properties not just those at the top level, so since you did not specify "a" and "b" in your array they where not included in the final string.

Try JSON.stringify(obj,["x","y","z", "a", "b"]);http://jsfiddle.net/mowglisanu/rhCTY/

Post a Comment for "Json.stringify Filter For Properties With Object Values Is Not Working"