format · validate · convert · runs locally

Parse JSON in Node.js

How to parse a JSON string into an object and serialize (stringify) an object back to JSON in Node.js. Node.js exposes the same global JSON.parse/JSON.stringify as the browser; .json files can be require()d or imported directly. Need to clean up the JSON first? Use the formatter & validator.

Parse JSON (string → object)

// built in, no import needed
const obj = JSON.parse(text);
// or read a file:
const obj2 = require('./data.json');

Stringify (object → JSON string)

const text = JSON.stringify(obj, null, 2);

Frequently asked questions

How do I parse JSON in Node.js?

Node.js exposes the same global JSON.parse/JSON.stringify as the browser; .json files can be require()d or imported directly. Parse with the snippet above; the result is a native object/map you can read.

How do I pretty-print JSON in Node.js?

Use the stringify snippet above with indentation, or paste your JSON into the formatter on this page.