JS Object to JSON Converter
Convert a JavaScript object literal to strict JSON online. Handles unquoted keys, single quotes, trailing commas and comments — without eval.
What is the JS Object to JSON Converter?
The ByteTools JS Object to JSON Converter turns JavaScript and JSON5-style object literals into strict, valid JSON.
- Unquoted keys, single quotes, trailing commas and comments accepted
- Never executes your code — no eval, no Function constructor
- undefined, NaN and Infinity converted to null with warnings
- Strips const/let/var and module.exports wrappers automatically
- Precise error messages with line and column numbers
- 100% private — code never leaves your browser
How to use the JS Object to JSON Converter
- 1
Paste a JavaScript object or array literal — a const x = wrapper is fine.
- 2
Choose the output indentation (2 spaces, 4 spaces, tabs or minified).
- 3
Click Convert to JSON.
- 4
Review any warnings, then copy or download the strict JSON.
About the JS Object to JSON Converter
The ByteTools JS Object to JSON Converter turns JavaScript and JSON5-style object literals into strict, valid JSON. It accepts everything JSON.parse rejects: unquoted keys, single-quoted and template strings, trailing commas, // and /* */ comments, hex numbers, and even a leading const config = wrapper, which is stripped automatically.
It uses a hand-written tokenizer and recursive-descent parser — your code is never executed and the tool never calls eval or new Function. Values that have no JSON equivalent, such as undefined, NaN and Infinity, are converted to null with a clear warning so nothing changes silently.
It is perfect for developers copying an object out of a JS config file, a console dump or documentation and needing real JSON for an API call or a .json file. Everything runs 100% locally in your browser; nothing you paste is uploaded or stored.
Frequently asked questions
How do I convert a JavaScript object to JSON?
Paste the object literal and click Convert to JSON. The tool parses it with its own tokenizer — handling unquoted keys, single quotes, trailing commas and comments — and outputs strict JSON with your chosen indentation.
Is my code executed to do the conversion?
No, never. The converter is a real parser, not eval. It reads your text token by token and builds the value structurally, so pasting untrusted code snippets cannot run anything in your browser.
What happens to undefined, NaN or Infinity?
JSON has no representation for them, so each becomes null and a warning tells you the substitution happened. Functions, dates and other expressions are rejected with a clear error instead of being silently dropped.
Does it accept JSON5?
The common JSON5 features, yes: unquoted identifiers as keys, single-quoted strings, trailing commas, comments, hex numbers and leading plus signs. Template strings work too, as long as they contain no ${…} interpolation.
Why not just wrap my object in JSON.parse?
JSON.parse requires strict JSON — double quotes, no comments, no trailing commas — so real-world JS literals fail immediately. This tool bridges that gap without you hand-editing quotes and commas.
Related tools
JSON Formatter
Format, beautify and minify JSON online with 2-space, 4-space or tab indentation. Sort keys alphabetically and catch syntax errors instantly — free and private.
JSON Validator
Free online JSON validator: validate JSON and find syntax errors with the exact line and column. See root type, key counts and depth — instant and 100% private.
PHP Array to JSON Converter
Convert PHP array literals to JSON online. Parses array() and [] syntax, => keys, nesting and quotes, and outputs lists as real JSON arrays.
JSON to TypeScript
Generate TypeScript interfaces from a JSON sample online. Infers types recursively, merges array shapes and marks optional keys — 100% in your browser.
JSON Viewer
View JSON as a collapsible interactive tree online. Expand and collapse nodes, search keys and values, and copy the JSONPath of any node privately.