Reputation: 1253
I am using angular formly to generate some forms. I'm retrieving the form definition from my database, which is multiple json objects. In javascript how to I convert (for example) the following string into an array of objects?
"{"template": "<h2>MAIN HEADING.</h2>"
},
{
"template": "<h4>sub heading.</h4>"
}"
Upvotes: 1
Views: 264
Reputation: 141839
Just wrap it in []
so it becomes a JSON array, and then parse it:
var result = JSON.parse( '[' + str + ']' );
Upvotes: 4