Javascript Object to JSON
The JavaScript Object to JSON tool transforms regular JS objects into JSON with proper formatting. Use it to beautify your data, debug structures, and prepare payloads for APIs.
The JavaScript Object to JSON tool transforms regular JS objects into JSON with proper formatting. Use it to beautify your data, debug structures, and prepare payloads for APIs.
Use this tool to convert JavaScript object literals (with single quotes or unquoted keys) to properly formatted JSON. Ideal for developers working with APIs or needing strict JSON syntax.
Input:
{ name: "Alice", age: 25 }
Output:
{
"name": "Alice",
"age": 25
}
A JavaScript object literal is more permissive than JSON. JSON, defined by RFC 8259, requires double-quoted keys and strings, forbids trailing commas and comments, and allows only objects, arrays, strings, numbers, true, false and null. This tool reads the looser syntax with its own safe parser instead of running your text as code. It accepts unquoted keys, single-quoted and backtick strings, trailing commas, comments, hexadecimal and binary numbers, numeric separators, and the words undefined, NaN and Infinity. It then writes standard JSON using two-space indentation, so { name: 'Ann', tags: ['a',] } becomes a valid quoted version.
Some JavaScript values simply cannot be represented in JSON, and the final step follows the rules of JSON.stringify. Properties whose value is undefined are removed from objects, and undefined inside an array becomes null. NaN and Infinity are written as null. Because the parser never executes the text, anything that needs evaluation is rejected with an error and a position. That includes function calls, variables, arithmetic, arrow functions, and template literals containing a dollar-brace expression. Only literal data is converted, which also protects you when pasting unfamiliar snippets.
No. Everything runs in your browser and never leaves your device.
The tool will show an error message for invalid input syntax.
Yes, but more user-friendly and handles JS-style object input directly.
No. It uses a restricted literal parser that only reads data such as objects, arrays, strings, numbers and booleans. Function calls, variables, and operators are rejected, so nothing in the input is ever executed.
JSON has no representation for those numbers, so the standard stringify rules write them as null. The same rule is applied when they appear in your object.