I've read several posts on using JSON.stringify
to pretty print a JSON string with Javascript. However, it seems to re-order the nodes. I would like to have a formatted JSON object in the same order as the string provided.
Here's an example of what I get using the prescribed methods
var sJson = '{"2":"stuff", "1":"care"}';
alert(JSON.stringify(JSON.parse(sJson), null, 2));
Result:
{
"1": "care",
"2": "stuff"
}
Desired Result:
{
"2": "stuff",
"1": "care"
}
I'm happy to use an external library if JSON.stringify
is unable to do this. Note: I'm starting with a minified JSON string from the server.