1var mystr = '{ "hello":"world" }' // NB: Has enclosing ""
2var myobj = JSON.parse(mystr);
1var jsonPerson = '{"first_name":"billy", "age":23}';
2var personObject = JSON.parse(jsonPerson); //parse json string into JS object
1Use the JavaScript function JSON.parse() to convert text into a JavaScript object:
2var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
1
2const obj = JSON.parse('{"assetType": "OPTION",
3"putCall ": "CALL",
4"contractType": "CALL",
5"strikePrice": "700",
6"premium": "6.00",
7"comment": "",
8"parsed": true }');
9
1str = "firstName:name1, lastName:last1"; // NB: No enclosing ""
2obj = eval('({' + str + '})');