Data Format Conversions

JavaScript Object to JSON Converter

Convert JavaScript object and array literals to valid JSON: unquoted keys, single quotes, comments, trailing commas, undefined and export default / const wrappers are all handled, and nothing is run with eval. Big integers stay exact.
Runs in your browserLive result

Workspace

Options

[1, 2, 3] instead of one item per line.

How to use this tool

  1. 1Paste a JavaScript object, array or a const/export of one, or open a .js file.
  2. 2Read any notes about values JSON cannot hold (undefined, NaN, tuples…).
  3. 3Choose indentation and key sorting.
  4. 4Copy or download the .json file.

Frequently asked questions

No. A dedicated parser reads the literal; nothing is run with eval or new Function. Variables, function calls and spread (...) are reported as errors with their line and column instead.

They have no JSON form. Properties set to undefined are left out and NaN/Infinity become null, exactly as JSON.stringify does, and a note tells you this happened.

Yes. export default { … }, module.exports = { … } and const name = { … } wrappers are understood. Several exported constants become one JSON object keyed by name.

No. Numbers keep their original digits, so IDs like 12345678901234567890 are not rounded as they would be by JSON.parse and JSON.stringify.