JS Object to JSON ConverterFix Quotes & Trailing Commas

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.

Your input is never sent anywhere.

Details
JSON
Your result appears here
Indent

Fixes 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

  1. Choose the output: JSON, JS object, or TypeScript.
  2. Paste your object or JSON into the input box. The result updates as you type.
  3. Set the options: indent, sorted keys, quote style, or the TypeScript root name and declaration style.
  4. 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.

FeatureJavaScript objectStrict JSONIn this tool
QuotesSingle, double, or backtickDouble quotes onlyWritten with double quotes in JSON
KeysCan be unquotedMust be double-quoted stringsQuoted in JSON; optionally unquoted in JS output
Trailing commaAllowedSyntax errorRemoved
Comments// and /* */Not allowedRemoved
undefinedAllowedNot allowedDropped from objects, null in arrays
NaN and InfinityAllowedNot allowedWritten as null
Number formatsHex, octal, binary, .5, 5., 1_000, +1Decimal only, no leading zerosWritten as plain decimal numbers
FunctionsAllowedNot allowedRejected 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▼
Paste the object here with JSON selected. Keys and strings are rewritten with double quotes, and the chips show which fixes were applied. Copy the result into your request or file.

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▼
Convert the content to JSON here. Trailing commas and comments are removed, and the Fixed list tells you what was there. Keep the commented version only in files that use JSONC.

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▼
Check the notice under the editors. It reports how many undefined, NaN, or Infinity values were dropped or turned into null. Functions are rejected with an error, so remove them or replace them with data first.

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▼
Paste an array that contains several example objects. The tool merges them, makes keys optional when some items lack them, and adds | null where a value is null.

JS object to JSON FAQ

Q.How do I convert a JavaScript object to JSON?

Q.

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?

Q.

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?

Q.

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?

Q.

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?

Q.

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?

Q.

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?

Q.

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?

Q.

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?

Q.

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.

User Feedback & Request

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.

Send feedback