Hi,
We are trying to store JSON in our table but it seems that it is getting reformatted on save. This reformatting reorders the object keys in alphabetical order like so:
{“z”:“123”, “a”: “456” } gets reformatted to {“a”: “456”, “z”: “123”}
It’s important for us to keep the structure of our original JSON object. Is this something you can help with?
Thanks,
Matt
Hey Matt - JSON/Objects have no implicit ordering, unlike Arrays. The ordering of the keys (top to bottom) has no functional impact. Is it because you are printing the JSON to a console, or writing it to a file, and want to maintain a categorized order?
If that’s the case, I’d recommend using an Array, or avoiding the JSON field altogether and saving a String of your data.
Array : [[“z”, “123”], [“a”, “456”]]
Saving this array would maintain the ordering, which you could then write a function to reduce it back to an object or print it in order.
String : ‘{“z”:“123”,“a”:“456”}’
Running JSON.stringify({“z”:“123”, “a”: “456” }) on your object would return the string you’d save, which then after querying could be restored using JSON.parse(’{“z”:“123”,“a”:“456”}’).