← All text tools

JavaScript Object to JSON Converter

Convert a JavaScript object literal with unquoted keys, single quotes, comments and trailing commas into strict, valid JSON.

  • Free
  • No sign-up
  • Works on any device

About JavaScript Object to JSON Converter

A JavaScript object literal is not valid JSON: keys may be unquoted, strings may use single quotes or backticks, and comments and trailing commas are allowed. This tool reads such a literal without running it, so nothing in the text can execute, and writes strict JSON with double-quoted keys. It also accepts hexadecimal numbers, line continuations and a leading const data = or export default, and reports the line and column of the first error. Pick two spaces, four spaces, tabs or a minified single line. Values that JSON cannot hold, such as undefined or NaN, are dropped or written as null with a note.

How to use JavaScript Object to JSON Converter

  1. Paste the object literal, or the whole const x = {...} line.
  2. Choose the output style: two or four spaces, tab or minified.
  3. Copy the JSON, or read the line and column of the first error and fix it.

Why use this tool?

Also known as

Frequently asked questions

Does the converter use eval to read my object?

No. It has its own parser, so functions and other code in the pasted text cannot run. Anything that is not data, such as a function call, is reported as an error.

What happens to undefined and functions?

JSON has no undefined, so a property with that value is left out of objects and written as null inside arrays. Functions are not data and cause an error.

Can it read JSON5 as well?

Yes for the parts that matter in practice: unquoted keys, single-quoted strings, comments, trailing commas, hexadecimal numbers and plus signs. Output is always strict JSON.

Is JavaScript Object to JSON Converter free?

Yes. JavaScript Object to JSON Converter on Toolipedia is free to use, with no sign-up and no watermark.

Is it safe to use?

Yes. Everything is worked out in your browser, and nothing you enter is sent to our server.

Does it work on my phone?

Yes. It works in any modern browser on Android and iPhone, as well as on tablets and computers. There's nothing to install.

Do I need an account?

No. Just open the page and use the tool. There's no sign-up and no email needed.

Can I put JavaScript Object to JSON Converter on my own website?

Yes. Use the Embed on your site button under the tool to copy a short piece of code and paste it into your page. It is free, needs no account, and the tool keeps working inside your page.

Related tools