Sometimes, we want to convert JSON string to array of JSON objects in JavaScript.
In this article, we’ll look at how to convert JSON string to array of JSON objects in JavaScript.
How to convert JSON string to array of JSON objects in JavaScript?
To convert JSON string to array of JSON objects in JavaScript, we use the JSON.parse
method.
For instance, we write
const str = '[{"id":1,"name":"Test1"},{"id":2,"name":"Test2"}]';
const dataObj = JSON.parse(str);
to call JSON.parse
with str
to convert the string to an array of objects and return it.
Conclusion
To convert JSON string to array of JSON objects in JavaScript, we use the JSON.parse
method.