Skip to content

Practical JSON · Parsing and Stringifying

All tutorials

Parsing and Stringifying

In JavaScript: JSON.parse() converts a JSON string into an object. JSON.stringify() does the opposite. Other languages have equivalents (json.loads/json.dumps in Python, json_decode/json_encode in PHP).

// Parse: string → object
const str = '{"name":"Alice","age":30}';
const obj = JSON.parse(str);
console.log(obj.name); // "Alice"

// Stringify: object → string
const json = JSON.stringify(obj);
// Pretty-print with 2-space indent
const pretty = JSON.stringify(obj, null, 2);