I'm trying to convert an array of arrays to a list of JSON objects.
var headers = ['first name','last name','age']
var data = [ [ 'John', 'Gill', '21' ], [ 'Sai', 'Varun', '21' ] ]
When we use the above two lists to generate a list of JSON's, output will be like,
[ { 'First name': 'John', 'Last name': 'Gill', age: '21' },
{ 'First name': 'Sai', 'Last name': 'Varun', age: '21' } ]
But I'm in need of the output to be as, (double quoted strings and the JSON should not be a string but should be a JSON object)
[ {"First name":"John","Last name":"Gill","age":"21"},
{"First name":"Sai","Last name":"Varun","age":"21"} ]
I tried using JSON.stringify
but the result won't be a JSON object
right, it'll be a JSON string
which would prevent accessing each of the JSON's from the list as a whole.
I have gone through many such answers but in vain. Can someone shed some light on this?!
JSON.stringify
which I have already mentioned in the answer.JSON.parse(JSON.stringify(data))
?data
right?!