Skip to content

JavaScript to JSON Online Converter — Numio

Turns a JavaScript object literal into strict, 2-space-indented JSON. Unquoted keys, single quotes, comments, trailing commas, hex numbers and leading-dot decimals are accepted and normalized.

Copying a config or fixture object out of a .js file into a JSON file, API request body or Postman collection.

Accepts JSON and JSON5, including comments, single quotes and trailing commas. Functions and JavaScript expressions are not executed.

JS Object

JSON

When to use it

  • Copying a config or fixture object out of a .js file into a JSON file, API request body or Postman collection.
  • Cleaning up an object pasted from browser DevTools or documentation so it passes a strict JSON parser.

How to use

  1. Paste the object literal (data only, no variable declaration or trailing semicolon) into the left editor, or use the load-file button to open a UTF-8 file.
  2. The JSON appears on the right as you type; if an error such as "invalid character" appears, check the reported line and column.
  3. Review the converted values (hex becomes decimal, quotes become double quotes) and copy the result.

JavaScript object literal

{
  // Mongoose-style field definition
  title: {
    type: 'String',
    required: true,
  },
  year: { type: 'Number', max: 0x7E6 },
  tags: ['draft', 'review',],
  ratio: .75,
  'content-type': "text/plain",
}

JSON

{
  "title": {
    "type": "String",
    "required": true
  },
  "year": {
    "type": "Number",
    "max": 2022
  },
  "tags": [
    "draft",
    "review"
  ],
  "ratio": 0.75,
  "content-type": "text/plain"
}

Details and limitations

Input is parsed with the JSON5 parser in your browser; the code is never executed. Expressions, functions, new Date(), template literals, undefined and variable references are rejected as invalid characters.

NaN and Infinity are rejected with an error because JSON cannot represent them.

Comments and the original key order formatting are not kept; output always uses double quotes and 2-space indentation.

Integers beyond 2^53 lose precision (12345678901234567890 becomes 12345678901234567000). Quote large IDs as strings.

FAQ

Can I paste const config = { ... };?

No. Only the value is accepted. Remove the declaration and the trailing semicolon, otherwise the parser reports an invalid character at that position.

What happens to duplicate keys?

The last occurrence wins. {a: 1, a: 2} becomes {"a": 2} without a warning, so check objects that were merged by hand.

Does it accept arrays or single values at the root?

Yes. Any JSON5 value works, for example [1, 2,] becomes a two-element JSON array and 'hi' becomes "hi".

Specifications and references