JavaScript JSON Parse

Note: JSON.parse() does not allow trailing commas
Note: JSON.parse() does not allow single quotes
w3 JSON Parse | Plain English JSON Parse | ** Educative JSON Parse ** | JS Info JSON Parse | * MDN JSON Parse *

MDN Polyfill JSON Parse | ** Digital Ocean JSON Parse ** | * Digital Ocean Resources * | Mr Data Converter |

    const json = '{"result":true, "count":42}';
    const obj = JSON.parse(json);
    
    console.log(obj.count);
    // expected output: 42
    
    console.log(obj.result);
    // expected output: true
  




Example - Parsing JSON

Imagine we received this text from a web server:

'{"name":"John", "age":30, "city":"New York"}'

Use the JavaScript function JSON.parse() to convert text into a JavaScript object:

const obj = JSON.parse('{"name":"John", "age":30, "city":"New York"}');

Note: Make sure the text is in JSON format, or else you will get a syntax error.



Last Updated:

Sunday November 14 2021 1047 AM