usr30911
usr30911

Reputation: 2791

Change JSON structure using JS

I have a json in my html page with the following format

{
    "data": [
        {
            "values": [
                [
                    894306600000,
                    1342
                ],
                [
                    894393000000,
                    749
                ]
            ],
            "key": "Beverages"
        }
    ]
}

i want to copy this json from one variable to another in this format

  [
        {
            "values": [
                [
                    894306600000,
                    1342
                ],
                [
                    894393000000,
                    749
                ]
            ],
            "key": "Beverages"
        }
    ]

How do i access the inner childs in this hierarchy

Upvotes: 0

Views: 618

Answers (1)

Ferdi265
Ferdi265

Reputation: 2969

you can access child keys with the object.key or the object['key'] notation.WIth arrays, just use array[index]

var before = JSON.parse(first_JSON);
var after = before.data;
var second_JSON = JSON.stringify(after);

Upvotes: 4

Related Questions