Skip to content

Instantly share code, notes, and snippets.

@djD-REK
Last active June 2, 2020 18:15
Show Gist options
  • Save djD-REK/619651d380d18f35ac4f9523151e8529 to your computer and use it in GitHub Desktop.
Save djD-REK/619651d380d18f35ac4f9523151e8529 to your computer and use it in GitHub Desktop.
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