Home › Developer Tools › JavaScript Object to JSON

JavaScript Object to JSON

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.
Advertisement
Advertisement

How to use the JavaScript Object to JSON

  1. Paste your object into the left box, drop a .js or .py file on it, or pick an example.
  2. Read the result: valid JSON appears on the right as you type, with a summary of what was converted.
  3. Choose how special values are handled: remove undefined keys like JSON.stringify, or keep them as null.
  4. Pick the formatting: indentation, sorted keys and ASCII-only escaping.
  5. 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

InputExampleJSON 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, BigInt0xFF, 0b101, 1_000, 9007199254740993n255, 5, 1000, 9007199254740993
Leading or trailing dot.5, 5.0.5, 5
Datenew Date('2026-03-14T09:30:00Z')"2026-03-14T09:30:00.000Z"
Function or method{ f() {}, g: () => 1 }keys removed
Python constantsTrue, False, Nonetrue, false, null
Python tuple and set(1, 2), {'a', 'b'}[1, 2], ["a", "b"]
Python Decimal, datetimeDecimal('9.90'), datetime.date(2024, 1, 2)9.90, "2024-01-02"
MongoDB shellObjectId("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.

Related tools

JSON Repair ToolFix broken JSON automatically: trailing commas, quotes, comments, truncated data, with a diff.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.JSON to Go StructTurn JSON into Go structs with inferred types, nested structs and json tags.SQL Create Table GeneratorDefine columns, keys, defaults and indexes; get CREATE TABLE SQL for MySQL, Postgres and more.SQL IN Clause GeneratorTurn a pasted list into a SQL IN ('a','b') clause with quoting, dedupe and 1,000-item chunks.SQL Online CompilerRun SQL queries online on SQLite with sample databases, a result grid, CSV export and .db save.SQL to ER DiagramPaste CREATE TABLE statements and get an entity-relationship diagram with keys and links.XML to XSD GeneratorGenerate an XML Schema (XSD) from sample XML: types, occurrences, attributes and namespaces.XML ValidatorCheck if XML is well-formed, see the exact line and column of each error and pretty-print it.Wildcard Mask CalculatorConvert a subnet mask or CIDR to a wildcard mask for ACLs and OSPF, with range and binary.CSV to VCF ConverterConvert a contacts CSV into a vCard (.vcf) file, mapping columns to name, phone, email and more.CSV to YAML ConverterConvert CSV rows to a YAML list of mappings with type inference and delimiter detection.Endianness ConverterSwap byte order of 16, 32 and 64-bit hex values and see big- and little-endian integers and floats.Excel to SQL ConverterTurn an Excel sheet into CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.Excel to VCF ConverterTurn an Excel contact list into a vCard .vcf file for iPhone, Android, Google or Outlook.File to C ArrayConvert any file into a C or C++ byte array header, like xxd -i, with const and PROGMEM options.Image to C ArrayConvert images to monochrome, RGB565 or RGB888 C arrays for OLED, LCD and TFT displays.JSON Merge ToolDeep-merge two or more JSON objects with array concat, replace or union and a conflict rule.JSONL to CSV ConverterConvert JSON Lines / NDJSON to CSV with flattened columns; streams large files locally.PHP Unserialize OnlineDecode PHP serialize() strings to JSON, a tree or print_r, and serialize JSON back to PHP.SQL Dialect ConverterTranslate SQL between MySQL, PostgreSQL, SQLite, SQL Server, Oracle, BigQuery and more.TSV to JSON ConverterTurn tab-separated data pasted from Excel or Sheets into a JSON array or keyed object.XLS to XLSX ConverterConvert old Excel 97-2003 .xls workbooks to modern .xlsx files in your browser, several at once.XML to Excel ConverterTurn repeating XML elements into an .xlsx spreadsheet with attributes and nested data as columns.XSD to XML Sample GeneratorGenerate a sample XML document from an XSD schema, with types, attributes and namespaces.YAML to CSV ConverterTurn a YAML list of objects into CSV with dot-notation columns, custom column order and download.DOCX to Markdown ConverterConvert Word .docx to clean Markdown with headings, lists, tables, links and images in a ZIP.ES6 to ES5 ConverterTranspile modern JavaScript (ES2015+) to ES5 with Babel: targets, module format and loose mode.JSON Graph VisualizerSee JSON as an interactive node graph with zoom, collapse and search; export PNG or SVG.KML ViewerOpen KML and KMZ files on an interactive map: placemarks, paths, polygons, folders, export.MySQL to PostgreSQL ConverterConvert MySQL dumps and CREATE TABLE statements to PostgreSQL: types, AUTO_INCREMENT, ENUMs, quotes.Text to CSV ConverterTurn space-aligned, fixed-width, pipe or tab separated text into clean CSV with a live preview.VCF File ViewerOpen vCard .vcf files as contact cards with photos, search and duplicate check, export CSV.
See all 129 Data & File Format Converters →