Zero Signup ToolsFree browser tools

Converter Tools

JS Object to JSON Converter

Convert JavaScript object literals to valid JSON in your browser. Handles unquoted keys, single quotes, trailing commas, comments, and undefined.

JS Object to JSON Converter

Output

Convert any JS object literal to strict JSON

Accepts unquoted keys, single quotes, template literals, trailing commas, comments, hex / octal / binary numbers, and the special values undefined, NaN, and Infinity. The output is RFC 8259 JSON that parses cleanly with JSON.parse.

Up to 400,000 characters. Parsing runs entirely in your browser, so nothing is uploaded.

What this fixes that JSON.parse will not

  • Unquoted keys: { name: "Ada" } becomes { "name": "Ada" }.
  • Single quotes and template literals are converted to double-quoted JSON strings with proper escapes.
  • Trailing commas in arrays and objects are removed, including holes like [1, , 3] (which become null).
  • // line comments and /* block comments */ are stripped.
  • Hex (0x), octal (0o), and binary (0b) numbers are rewritten as decimal.
  • Numeric separators like 1_000_000 are removed. Leading-zero numbers are coerced to decimal with a warning.
  • undefined, NaN, Infinity become null on output. The count of replacements appears in the result strip so you can spot them.
  • A const foo = or let foo = prefix and a trailing semicolon are tolerated, so you can paste a whole variable declaration directly.

What is intentionally not supported

  • Variable references and function calls. The input must be a self-contained value, not a JS program. Replace identifiers like BASE_URL with their literal values before converting.
  • Template interpolations ${expression}. There is no value to substitute, so the parser stops with a clear error.
  • BigInt literals 10n. JSON has no native bigint type. Wrap in quotes if you need to round-trip them as strings.
  • Methods and getters on objects. JSON is data, not behavior.
  • Spread syntax ...other in arrays and objects. Materialise the spread into concrete values first.
  • RegExp literals /foo/g. Pass the regex source as a string instead.

How to use

  1. Paste a JS object literal (or array, string, or value) into the input on the left, or click Load sample to see a worked example.
  2. Pick an output format. Minify produces a single line; 2 or 4 space indent produces pretty-printed JSON.
  3. Read the JSON on the right with byte and key counts. Chips appear when undefined or NaN values were replaced with null.
  4. Check the warning list for duplicate keys, array holes, leading-zero numbers, and other lossy fixes the converter applied.
  5. Click Copy JSON to put the result on your clipboard, ready to paste into a config file or send through an API.

About this tool

JS Object to JSON Converter takes a JavaScript object literal and rewrites it as strict RFC 8259 JSON entirely in your browser. JSON is a small subset of JavaScript, so devs constantly hit the same paste-and-fail loop: the source uses unquoted keys, single-quoted strings, template literals, trailing commas, // and /* */ comments, hex (0x), octal (0o), and binary (0b) numbers, numeric separators like 1_000_000, leading + signs, or the special values undefined, NaN, and Infinity. JSON.parse rejects every one of those. This tool parses the lenient JS5 / JSON5 superset that real code uses and emits clean JSON that JSON.parse accepts without complaint. Keys get double quotes, strings get JSON-safe escapes, trailing commas are dropped, comments are stripped, exotic number bases are written as decimal, undefined inside objects is omitted (matching JSON.stringify), undefined in arrays plus NaN and Infinity become null, and the result panel shows the live byte count along with chips for how many undefined or non-finite values were replaced so the change is never silent. A const, let, var, or export prefix and a trailing semicolon are tolerated, so you can paste a whole variable declaration copied from your editor or browser DevTools and convert it without trimming. Parse errors include 1-based line and column numbers and a clear message so you can fix bad input quickly. Useful for cleaning up object literals copied from React state, Redux store snapshots, Vue data(), Jest snapshots, browser DevTools, Stack Overflow answers, ESLint configs, Tailwind configs, MDX frontmatter, and any other place where JSON is the data format but JavaScript is the source. Parsing and emission run locally on your device, so the code you paste here never leaves your browser.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsConverter Tools