I have the array in the following pattern:
[["abc","def"],["dss","ddd"]]
I need to convert it into an array of json objects:
[{"wf":"abc","sb":"def"},{"wf":"dss","sb":"ddd"}]
How would I do this?
Tim
2,9321 gold badge16 silver badges20 bronze badges
-
jsfiddle.net/tq9et7bo/15Umesh Sehta– Umesh Sehta2015年09月16日 05:04:10 +00:00Commented Sep 16, 2015 at 5:04
-
Thank you for the reply. Can it be made dynamic? I have lots of data to keep on the json format.SubSab– SubSab2015年09月16日 05:12:19 +00:00Commented Sep 16, 2015 at 5:12
-
what do you mean by dynamic what you want dynamic can you please explain?Umesh Sehta– Umesh Sehta2015年09月16日 05:13:59 +00:00Commented Sep 16, 2015 at 5:13
-
Thank you, it is working. I need like this only.SubSab– SubSab2015年09月18日 07:10:38 +00:00Commented Sep 18, 2015 at 7:10
1 Answer 1
Try this
var data= [["abc","def"],["dss","ddd"]];
var json = data.map(function (value, key) {
return {
"wf": value[0],
"sb": value[1]
}
});
console.log(json);
console.log(JSON.stringify(json)); // need string
answered Sep 16, 2015 at 5:05
Sign up to request clarification or add additional context in comments.
1 Comment
SubSab
Thank you for the reply.
lang-js