0

I have a JSON file like this:

"data": {
   "someKey": "some value",
   "anotherKey": {
     "someOtherKey": "some other value",
     "example": "here's another one"
   },
   "finalKey": {
     "thisOneShouldGoLast": "something",
     "nested": "some val",
   }
}

And I need to make it like this:

"data": {
   "anotherKey": {
     "example": "here's another one",
     "someOtherKey": "some other value"
   },
   "finalKey": {
     "nested": "some val",
     "thisOneShouldGoLast": "something"
   },
   "someKey": "some value",
}

So it's just ordering alphabetically by the keys. There can be more nesting levels but it will always be strings and objects.

I tried to google a solution but all I find is questions about how to sort arrays of objects based on a key and not this case.

nick
  • 2,397
  • 4
  • 26
  • 46

0 Answers0