Reputation: 707
I get a JSON data with this format:
{
key1: val1,
key2: val2,
key3: val3,
key4: val4,
..
}
Now I want to change it to another format in Javascript:
[
{key: "key1", value: value1},
{key: "key2", value: value2},
{key: "key3", value: value3},
{key: "key4", value: value4},
...
]
Is there some libraries that can do this? Or I have to write a function?
Please give me some tips! Thanx!
Upvotes: 1
Views: 89
Reputation: 129782
var newObject = Object.keys(originalObject).map(function(k) {
return { key: k, value: originalObject[k] };
});
Upvotes: 7