JS Object to JSON

Convert JavaScript object or array literals into valid JSON, supporting single quotes, unquoted keys, trailing commas and comments.

Settings

Usage

Features

This tool converts JavaScript object literals into valid JSON, automatically handling JS-only syntax such as single quotes, unquoted keys, trailing commas, comments, undefined/NaN/Infinity and hexadecimal numbers.

Steps

Enter or paste a JS object or array literal in the left text box and choose an indentation. Valid JSON is generated in real time on the right; click the Copy button to copy the result.

Configuration

  • Indentation: controls the indentation of the output JSON, supporting 2 spaces, 4 spaces and Tab.
  • Input accepts object literals, array literals, or any JS expression.
  • Non-JSON values such as undefined, NaN and Infinity are normalized to null to keep the output valid.
  • Values that cannot be JSON-serialized, such as functions and regular expressions, become null.

Notes

Input is evaluated as a JavaScript expression, so do not paste sensitive or destructive code. undefined, NaN, Infinity, functions and Symbols become null, Dates become ISO strings, and BigInts become strings.