Saturday, 17 August 2013

Manipulation json

Manipulation json

I have an javascript array object that looks like something below
var Array =
[{"foo1":"bar1","foo2":"bar2","foo3":"bar3","foo4":"bar4","foo5":"bar5","foo6":"bar6","foo7":"bar7"},
{"foo1":"bar5","foo2":"bar6","foo3":"bar7","foo4":"bar8","foo5":"bar9","foo6":"bar10","foo7":"bar10"}]
I want this array to be converted to a json formatted string for
serializing which looks something like. I am using JSON.stringify for
serializing which should give me the resulting string like the one below
'"fooAry" : [{"foo1":"bar1","foo2":"bar2","foo3":"bar3","foo4":"bar4"},
{"foo1":"bar5","foo2":"bar6","foo3":"bar7","foo4":"bar8"}]'
As you can see there are two things here
Getting rid of the last 3 elements of the key values pairs inside the array
appending the key "fooAry" to the resulting json string.

No comments:

Post a Comment