Last active
June 2, 2020 18:15
-
-
Save djD-REK/619651d380d18f35ac4f9523151e8529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const greetings = JSON.stringify({Hello: 'World!'}) | |
console.log(greetings) // {"Hello":"World!"} | |
console.log(JSON.parse(greetings)) // Object { Hello: "World!" } | |
// JSON requires double quotes: | |
JSON.parse("{\"Hello\":\"World!\"}") // Object { Hello: "World!" } | |
JSON.parse(`{"Hello":"World"}`) // Object { Hello: "World!" } | |
try { | |
JSON.parse("{'Hello':\"World!\"}") | |
} catch(e) { console.log(e) } // SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data | |
try { | |
JSON.parse("{\"Hello\":'World!'}") | |
} catch(e) { console.log(e) } // SyntaxError: JSON.parse: unexpected character at line 1 column 10 of the JSON data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment