I've encountered a problem with conversion list of individual JavaScript object to proper JavaScript array.
The list looks like below:
{ "property1": "value", someArray: [123], "property2": [] }
{ "property1": "value", someArray: [123], "property2": [] }
{ "property1": "value", someArray: [123], "property2": [] }
{ "property1": "value", someArray: [123], "property2": [] }
{ "property1": "value", someArray: [123], "property2": [] }
So, as you can see there two things which I need to take care of:
- Adding missing commas
- Create array from it.
To parse this response I'm using node JS. I've tried to convert this to array as follows:
const array = `[${response.data}.replace(/}/g, '},')}{}]`
Firstly I'm wrapping everything with array, add commas, and one empty object to get rid of last unwanted comma.
If I look at output everything seems ok, but when I'm trying to parse it with JSON.parse() I'm receiving
Unexpected ']' on position n
I'm not sure whether I'm doing something wrong or that data is corrupted since it is so long.