DEV Community

Discussion on: The secret power of JSON stringify

 
getclibu profile image
Neville Franks

Thanks for that. Pity it is missing from the MDN Doc's. For some reason the links didn't take me to the relevant sections.

Thread Thread
 
sidvishnoi profile image
Sid Vishnoi

Updated links. DEV included trailing : in links, so they broke.

Thread Thread
 
getclibu profile image
Neville Franks

Thanks, the links now work.

I didn't pick up on the ", but with limitation of maximum object depth 1" issue and I need to handle objects with depth > 1.

After some more searching I found this article which is a collection of code snippets. tfzx.net/article/499097.html

The code that worked for me is:

    var allKeys = [];
    JSON.stringify( json, function( key, value ){ allKeys.push( key ); return value; } )
    allKeys.sort();
Enter fullscreen mode Exit fullscreen mode

which is from: stackoverflow.com/a/53593328/91300