0

I have the following data-structure:

{
    "Category": "cars",
    "Limit": "10",
    "Properties": [
        {
            "value": "red",
            "key": "colour"
        },
        {
            "value": "bmw",
            "key": "make"
        },
        {
            "value": "estate",
            "key": "body"
        }
    ],
    "Offset": "0"
}

I need to rebuild it so that it looks like this:

{
    "Category": "cars",
    "Properties[0][key]": "colour",
    "Properties[1][key]": "make",
    "Properties[2][key]": "body",
    "Properties[2][value]": "estate",
    "Properties[0][value]": "red",
    "Limit": "10",
    "Offset": "0",
    "Properties[1][value]": "bmw"
}

Rather than re-inventing the wheel, are there any utilities that can assist here ? Or can somebody please provide some best advise regarding the best way to achieve this.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
user1513388
  • 7,165
  • 14
  • 69
  • 111
  • 1
    I'm afraid that you have to build your own script for this. You will have to use recursion for that. – DontVoteMeDown Nov 12 '14 at 16:06
  • The most relevant utility I can think of is underscore.js. It has a bunch of functions for manipulating arrays, but none of them do quite what you want here. You'll have to right your own algorithm, most likely. – Raphael Serota Nov 12 '14 at 16:09
  • 1
    Possible duplicate: [Fastest way to flatten / un-flatten nested JSON objects](http://stackoverflow.com/questions/19098797/fastest-way-to-flatten-un-flatten-nested-json-objects) – Greg Burghardt Nov 12 '14 at 16:20

0 Answers0