Back to Tools

JS to JSON Converter

Convert JavaScript Objects/Arrays into valid JSON strings

JavaScript Tool
JS Object/Array

From JavaScript object literal to strict JSON

A JavaScript object such as { name: 'Dev', id: 101 } is not valid JSON: the key has no quotes and the string uses single quotes. Config files, APIs and most parsers want the strict form. This converter evaluates the literal you paste and outputs it as properly quoted, four-space-indented JSON.

Converting an object

  1. Paste a JS object or array into the JS Object/Array box. Load Sample fills in a small app description with a features list.
  2. Decide whether to keep Strip Functions (Keep Data Only) ticked. It is on by default.
  3. Click Convert to JSON.
  4. Copy the text from the JSON Result panel with the Copy button.

If the input cannot be evaluated, a browser alert says Invalid JS Object. Nothing is changed in the input, so you can fix the problem and try again.

What you can paste

  • Object literals with unquoted keys, single-quoted or backtick strings, and trailing commas.
  • Arrays of objects, nested structures, numbers, booleans and null.
  • Expressions that produce a value, such as new Date() or 60 * 60, which are computed before conversion.

How JSON differs from JavaScript

JSON has no functions, no undefined and no comments. With stripping enabled, function properties are removed from the output. Properties whose value is undefined are dropped in every case, and inside arrays they become null. Dates become ISO strings, and values like NaN and Infinity become null. Numbers such as 1.0 print as 1.

Typical situations

  • Turning a config object copied from source code into a .json file.
  • Preparing sample data for an API request body or a mock server.
  • Cleaning up a snippet from documentation that uses JavaScript-style keys.
  • Converting data exported from a browser console into something a JSON tool accepts.

Safety note

To read your input, the tool actually evaluates it as JavaScript in your browser. That means any code inside the input will run, including function calls and network requests. Only paste literals you understand and trust, and never paste code from an unknown source. Conversion itself takes place on the page rather than through a server request. If the result looks wrong, check that every bracket and quote in the input is closed, because a single missing brace stops the evaluation and triggers the alert.

Related Tools


Frequently Asked Questions

Why is my JavaScript object not valid JSON?
JSON requires double-quoted keys and strings, and forbids functions, undefined, comments and trailing commas. A JavaScript literal can use all of those. This converter evaluates the literal and re-serializes it, so the output follows the strict JSON rules.
What happens to functions in my object?
With Strip Functions ticked, function-valued properties are removed. Even if you untick it, JSON cannot represent functions, so they are still omitted by the serializer. The option mainly matters for how the tool handles the replacer step.
Is it safe to paste any code here?
The input is evaluated as JavaScript in your browser to build the object, so it can execute whatever it contains. Paste only plain data literals that you trust, and avoid pasting code from unknown sources.
Does it accept a variable declaration like const a = {}?
No. It expects just the object or array expression. Remove the const, the name and the trailing semicolon, then convert. A declaration would fail and show the Invalid JS Object alert.
How is the JSON formatted?
The output is pretty-printed with four spaces of indentation. If you need a compact one-line version for an API request or a config value, copy the result and run it through a JSON minifier.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.