I have a NodeJS App that accepts a a string (uploaded input!) I have No Control over the input I am merely building a REST Service to Processes the data.
That string is meant to be an Array of JSON Objects that I can then loop through to extract each element ...
I'm receiving the following (as a string):
[
{Name: 'Jane',
Id: '005b0000000MGa7AAG'},
{Name: 'Tom',
Id: '005b0000000MGa7AAF'}
]
When I try to JSON.parse this I get
SyntaxError: Unexpected token N
Understandably so, because I know this is Invalid JSON
whereas This next string is valid JSON and passes http://jsonlint.com/:
[
{Name: Jack,
Id: 005b0000000MGa7AAA},
{Name: Jill,
Id: 005b0000000MGa7AAB}
]
My question is: How can I accept the first input and parse it to allow:
parsed[0]['Name'] == 'Jane'
>> true
My first instinct is to string replace the keys (e.g. Name to Name) and then try parsing it. But if anyone else has a solution, I'd be grateful.