Quiz Entry - updated: 2026.06.20
How do you convert a JSON string to a JavaScript object?
JSON.parse() deserialises a JSON string back into a usable JavaScript object.
let personJSON = '{"name":"Muster","vorname":"Hans"}';
let person = JSON.parse(personJSON);
// "Muster"
console.log(person.name);
// "Hans"
console.log(person.vorname);
Important: JSON.parse() throws an exception if the JSON is invalid!
try {
let data = JSON.parse(invalidJSON);
} catch (e) {
console.error("Invalid JSON:", e.message);
}
Common use cases:
- Receiving API responses
- Reading from localStorage
- Processing configuration files
Tip: Always wrap JSON.parse() in try-catch when parsing user input or external data.