Paste an object literal from JavaScript or TypeScript code, a console.log dump, a MongoDB shell document or a Python dict printed with print(). The converter parses it the way the language would and writes strict JSON with double-quoted keys, so you never have to fix quotes and commas by hand.
Last updated:
Ready.
What was converted
Advertisement
Advertisement
How to use the JavaScript Object to JSON
Paste your object into the left box, drop a .js or .py file on it, or pick an example.
Read the result: valid JSON appears on the right as you type, with a summary of what was converted.
Choose how special values are handled: remove undefined keys like JSON.stringify, or keep them as null.
Pick the formatting: indentation, sorted keys and ASCII-only escaping.
Copy or download the JSON. If something cannot be converted, the status bar shows the line and column to fix.
JavaScript and Python syntax and what it becomes in JSON
Input
Example
JSON output
Unquoted key
{ name: 'Ada' }
{"name": "Ada"}
Numeric key
{ 1: 'a', 2.50: 'b' }
{"1": "a", "2.5": "b"}
Single quotes / template literal
'it\'s', `dark`
"it's", "dark"
Trailing comma
[1, 2, 3,]
[1, 2, 3]
undefined
{ a: undefined } / [undefined]
key removed / [null]
NaN, Infinity
{ x: NaN }
{"x": null}
Hex, binary, separators, BigInt
0xFF, 0b101, 1_000, 9007199254740993n
255, 5, 1000, 9007199254740993
Leading or trailing dot
.5, 5.
0.5, 5
Date
new Date('2026-03-14T09:30:00Z')
"2026-03-14T09:30:00.000Z"
Function or method
{ f() {}, g: () => 1 }
keys removed
Python constants
True, False, None
true, false, null
Python tuple and set
(1, 2), {'a', 'b'}
[1, 2], ["a", "b"]
Python Decimal, datetime
Decimal('9.90'), datetime.date(2024, 1, 2)
9.90, "2024-01-02"
MongoDB shell
ObjectId("65f…"), NumberInt(42)
"65f…", 42
Tips for clean conversions
Copy from the console carefully. Browser consoles collapse long objects into {…} and arrays into Array(20). Right-click the object and use "Copy object" (Chrome, Edge) to get full text, or log JSON.stringify(obj, null, 2) directly.
Python print() vs json.dumps().print(d) writes Python repr with single quotes and True/None, which is not JSON. In your own code, json.dumps(d, indent=2, default=str) is the reliable way; this converter is for output you already have.
Key order is kept. Keys stay in source order, including numeric-looking keys that a JavaScript engine would move to the front. Turn on sorting for stable diffs.
Duplicate keys. In both JavaScript and Python the last value wins, so the converter keeps the last one and tells you which key was repeated.
Big IDs. Numbers above 9,007,199,254,740,991 lose precision when read by JavaScript's JSON.parse. The output keeps every digit, but consider storing such IDs as strings.
Frequently asked questions
What is the difference between a JavaScript object and JSON?
JSON is a strict text format derived from JavaScript object syntax. In JSON every key must be a double-quoted string, strings use double quotes only, trailing commas and comments are not allowed, and the only values are strings, numbers, true, false, null, objects and arrays. A JavaScript object literal allows unquoted keys, single quotes, template literals, trailing commas, comments, undefined, functions and expressions, so most real code is not valid JSON as written.
Why not just use JSON.stringify?
JSON.stringify works on a live object inside a running program. When you only have the source text, for example a snippet copied from code, documentation or a console log, you would have to evaluate it first, which is unsafe for untrusted text and fails when it references variables. This tool parses the text without executing anything and produces the same output JSON.stringify would for literal data.
What happens to undefined, functions and NaN?
JSON.stringify omits object keys whose value is undefined or a function, writes null for undefined or functions inside arrays, and writes null for NaN and Infinity. The converter follows the same rules by default, and you can switch to keeping such keys as null instead.
Can it convert a Python dictionary to JSON?
Yes. Output from print() or repr() of a dict converts directly: True, False and None become true, false and null, tuples and sets become arrays, single, triple-quoted and raw strings are handled, numeric keys become strings, and common reprs such as Decimal('1.5'), datetime.date(2024, 1, 2) and dict(a=1) are unwrapped.
What about variables and function calls in my object?
A reference like path.resolve(__dirname, 'dist') has no value until the program runs. With the default setting it is kept as a string so the rest of the data still converts; turn the option off to get an error at that exact position instead. Spread syntax and shorthand properties such as { a, b } always need values written out.
Does it handle very large numbers precisely?
Yes. Number text is copied digit for digit instead of being rounded through a double-precision float, so IDs larger than 2^53 stay exact. Hexadecimal, octal, binary and BigInt literals are converted to exact decimal with arbitrary precision.
Is my code sent anywhere?
No. Parsing and formatting happen in JavaScript on this page; nothing is uploaded, logged or stored except your option choices, which are remembered in your own browser.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.