Paste a JavaScript object and get valid JSON. Single quotes, unquoted keys, trailing commas, and comments are fixed for you, and you can also generate TypeScript types.
This tool runs entirely in your browser. What you enter is never sent anywhere.Your input is never sent anywhere.
DetailsFixes JS syntax
Quotes, keys, commas, and comments.
TypeScript types
Unions, optional keys, nested types.
Code is never run
Input is read as data only.
How to turn a JavaScript object into valid JSON
A JavaScript object literal and JSON look alike, but JSON is stricter. Paste an object copied from code or a console and the tool writes valid JSON that JSON.parse accepts. It fixes single quotes, unquoted keys, trailing commas, and comments, and it lists what it changed under the editors.
The input is read by a parser that only understands data, so your code is never executed. A function or a call such as new Date() is reported as an error instead of being run.
Use the other two tabs to go further. JS object turns JSON back into an object literal with the quote style you prefer, and TypeScript builds interfaces or type aliases from the data.
When an object has to become JSON
From a console or a code snippet
An object copied from DevTools or source code has unquoted keys and single quotes. Convert it before you use it as an API request body or a test fixture.
A config file that will not parse
A stray trailing comma or comment is enough to make a strict JSON file fail. Paste the file, copy the cleaned JSON, and check which fixes were needed.
TypeScript types for an API response
Paste a sample response and get interfaces with nested types, optional keys, and unions, instead of writing each field by hand.
JSON as a JavaScript object
Turn a JSON sample into an object literal with single quotes and unquoted keys, ready to paste into a test file or a config module.
Convert in 4 steps
- Choose the output: JSON, JS object, or TypeScript.
- Paste your object or JSON into the input box. The result updates as you type.
- Set the options: indent, sorted keys, quote style, or the TypeScript root name and declaration style.
- Click the copy icon, or the download icon to save data.json, data.js, or types.ts.
Note: A syntax error shows the problem with its line and column. When the input parses, the fixes that were applied appear as chips under the editors.
What the parser accepts and what it changes
- Accepted syntax: single, double, and backtick strings, unquoted keys, trailing commas, // and /* */ comments, hex, octal, and binary numbers, numeric separators, NaN, Infinity, and undefined.
- Wrappers: a leading const, let, or var declaration, export default, or module.exports = is skipped, and so is a final semicolon.
- Not accepted: functions, methods, classes, calls such as new Date(), regular expressions, spread, computed keys, shorthand properties, variable references, BigInt, and template literals with ${...}.
- JSON output: undefined properties are dropped, undefined array items and NaN or Infinity become null. This is the same result JSON.stringify gives.
- Keys: when a key appears twice, the last value wins. As in JavaScript, keys that are whole numbers are listed before the others.
- TypeScript: array items are merged into one type. A key missing from some items is optional, mixed types become a union, null is added as | null, and an empty array becomes unknown[]. Types are named after their keys, and identical shapes share one name.
JavaScript object syntax vs strict JSON
What each side allows, and what this tool does with the difference.
| Feature | JavaScript object | Strict JSON | In this tool |
|---|---|---|---|
| Quotes | Single, double, or backtick | Double quotes only | Written with double quotes in JSON |
| Keys | Can be unquoted | Must be double-quoted strings | Quoted in JSON; optionally unquoted in JS output |
| Trailing comma | Allowed | Syntax error | Removed |
| Comments | // and /* */ | Not allowed | Removed |
| undefined | Allowed | Not allowed | Dropped from objects, null in arrays |
| NaN and Infinity | Allowed | Not allowed | Written as null |
| Number formats | Hex, octal, binary, .5, 5., 1_000, +1 | Decimal only, no leading zeros | Written as plain decimal numbers |
| Functions | Allowed | Not allowed | Rejected with an error message |
Which files accept comments. tsconfig.json and VS Code settings files use JSONC, which allows comments and trailing commas. JSON.parse and most APIs do not, and package.json is read as strict JSON. Copying a snippet from one kind of file into another is a common cause of parse errors.
Your code is not run. The tool reads the text as data and has no upload step, so the content stays in your browser.
Debugging JSON errors and typing API data
Why a parse fails, what gets lost on the way to JSON, and what a generated type can and cannot know.
Why JSON.parse rejects an object that works in JavaScript
JSON.parse does not accept trailing commas, single-quoted property names, or numbers with leading zeros. Error text differs by browser, for example a message that expects a property name or a closing brace.
A parse error points at the place where the parser gave up, which is not always the place where the mistake is. Converting the object first removes the whole class of syntax problems.
What is lost when an object becomes JSON
JSON holds strings, numbers, booleans, null, arrays, and objects. undefined, functions, NaN, and Infinity have no place in it, so they are dropped or written as null.
The tool counts these changes and shows a notice, so a property that disappears does not go unnoticed before the data reaches an API.
A type from one sample describes only that sample
The TypeScript output is built from the data you paste. If a field is sometimes missing or sometimes null in real responses but present in your sample, the type will not show it.
Inside one array the tool merges every item, so a key missing from some items becomes optional. To cover more cases, paste an array that includes examples of each variant.
JSON, JSONC, and JavaScript config files
Strict JSON suits data sent between systems. JSONC, used by tsconfig.json and VS Code settings, adds comments and trailing commas for human-edited config. A JavaScript config module allows full object syntax.
If a tool expects strict JSON, run the content through this converter and check the chips to see what had to change.
Common mistakes with objects and JSON
Single quotes or unquoted keys break JSON.parse
An object copied from code or a console is passed straight to JSON.parse. The parser stops at the first single quote or unquoted key, and the error message gives only a vague position.
💡 See the solution▼
A trailing comma or comment in a strict JSON file
A snippet from tsconfig.json or a code example carries a trailing comma or a comment into a file that is read as strict JSON, such as package.json. The tool reading the file fails.
💡 See the solution▼
Properties vanish after the data becomes JSON
Keys whose value is undefined, or a function, disappear when an object is stringified, and a missing field can look like a bug on the API side.
💡 See the solution▼
A type that misses optional fields
A TypeScript interface built from one object marks every key as required. Real responses omit some keys or return null, and the code then fails at runtime.
💡 See the solution▼
JS object to JSON FAQ
Q.How do I convert a JavaScript object to JSON?
A. Paste the object into the input box with JSON selected as the output. The converter reads the object literal and writes valid JSON: keys and strings get double quotes, trailing commas and comments are removed, and numbers are written in plain decimal form. Copy the result or download it as data.json.
Q.Why does JSON.parse fail on my object?
A. JSON is stricter than JavaScript. JSON.parse rejects trailing commas, single-quoted strings and property names, unquoted keys, comments, and numbers with leading zeros. Paste the object here and the tool lists which of these it fixed, so you can see what was wrong.
Q.What happens to undefined, NaN, and Infinity?
A. JSON has no way to store them. In JSON output, a property whose value is undefined is dropped from the object, and an undefined array item becomes null. NaN and Infinity become null. A notice under the editors tells you how many values were changed. The JS object output keeps them as written.
Q.Is the code I paste executed?
A. No. The input is read by a parser that understands object and array literals only, and it is never run as code. A function, a method, or a call such as new Date() is rejected with an error message instead of being evaluated. The conversion happens in your browser, and the tool has no upload step.
Q.Can it handle const config = { ... } and export default?
A. Yes. A leading const, let, or var declaration, export default, or module.exports = is skipped, and so is a semicolon at the end. The chips under the editors show when a declaration was removed.
Q.How does the TypeScript output work?
A. Select TypeScript to get interfaces or type aliases. Nested objects become their own named types. In an array of objects, the shapes are merged: a key missing from some items becomes optional, and an array that mixes types becomes a union such as (number | string)[]. A null value becomes a union with null. You can set the root name and choose export.
Q.Can I turn JSON into a JavaScript object?
A. Yes. Select JS object. You can choose single or double quotes, unquoted keys where a key is a valid identifier, trailing commas, the indent, and sorted keys. Keys such as first-name that are not valid identifiers stay quoted.
Q.What kinds of input does the parser reject?
A. It reads plain data only. Functions, methods, classes, new Date() and other calls, regular expressions, spread syntax, computed keys, shorthand properties, references to other variables, BigInt values, and template literals with ${...} are rejected. The error message says what was found and gives the line and column.
Q.Is there a size limit?
A. The tool sets no size limit. The result is recalculated as you type, so a very large paste can feel slower on an older device. Data nested more than 200 levels deep is rejected.
Your feedback
makes this tool better.
Tell us which features you'd like, what should be fixed, or which new tool you'd like to see. An engineer reads every submission and uses it to guide development.