1

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?

4
  • jsfiddle.net/tq9et7bo/15 Commented 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. Commented Sep 16, 2015 at 5:12
  • what do you mean by dynamic what you want dynamic can you please explain? Commented Sep 16, 2015 at 5:13
  • Thank you, it is working. I need like this only. Commented Sep 18, 2015 at 7:10

1 Answer 1

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

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.