ryan pereira ryan pereira - 1 month ago 4
HTML Question

How to convert a JSON array into a JSON object in JavaScript or jQuery?

How do I convert a JSON array into a JSON object. For example, I have created a variable which holds a JSON array:

[{ "Bank Account Name": "State Bank",
"Currency Code": "4000",
"Deposit Date": "5/2/1794",
"Payment Channel": "check"}]


How do I convert it into a JSON object with entities as a JSON object which look like this:

{"Entities ":[{ "Bank Account Name": "State Bank",
"Currency Code": "4000",
"Deposit Date": "5/2/1794",
"Payment Channel": "check"}]
}


Is there a way to do this? I tried
Stringify
and
parse
.

Answer

var array = [{  "Bank Account Name": "State Bank",
    "Currency Code": "4000",
    "Deposit Date": "5/2/1794",
    "Payment Channel": "check"}];

var obj = {"Entities" : array};

console.log(obj);

Comments