Reputation: 21
I have a map where the keys of outer keys are fixed. But the keys of inner map are not fixed and it can be anything.
Example: [ "fixed_key1": "Hi, Let me know further details", "fixed_key2" : [ "unknow_key1" : "value1", "unknown_key2" : "value2", "unknown_key3" : "value3" ], "fixed_key3" : "End of json" ]
Now, when I marshal this to json in go
the order of keys is not reserved (order of outer and inner json) both are not preserved.
example: { "fixed_key3":"End of json", "fixed_key2":{ "unknow_key2":"value2", "unknown_key3":"value3", "unknown_key1":"value1" }, "fixed_key1":"Hi, Let me know further details" }
If you see after marshal the order of both outer and inner json is not preserved.
I want to preserve the order. **Correct order I want : ** { "fixed_key1":"Hi, Let me know further details", "fixed_key2":{ "unknow_key1":"value1", "unknown_key2":"value2", "unknown_key3":"value3" }, "fixed_key3":"End of json" }
How to achive it in go lang Go version: 1.19.4
Upvotes: -4
Views: 48