Skip to main content
Programming Language Tools

Code to JSON

Convert a loosely-formatted object/array literal (unquoted keys, single quotes, trailing commas) into strict, valid JSON.

Paste a JS/PHP-style object or array literal below - this tool normalizes common non-strict syntax into valid JSON.

This handles common non-strict patterns (unquoted keys, single quotes, trailing commas) - it isn't a general-purpose parser for arbitrary executable code.

What Does This Tool Do?

It accepts loosely-formatted, JSON-like data - unquoted object keys, single-quoted strings, trailing commas - and normalizes it into strict, standards-compliant JSON.

Why Use This Tool?

Data copied from JavaScript source code, a config file, or an AI-generated snippet often looks like JSON but isn't strictly valid - this tool fixes the common differences automatically instead of you editing every key and quote by hand.

How to Use It

  1. Paste your loosely-formatted object/array data.
  2. Click Convert.
  3. Copy the resulting strict, valid JSON.

Limitations

This handles common non-strict JSON-like patterns - it is not a general JavaScript/PHP code interpreter, so values that require actual code execution (function calls, variables) won't convert.

Example

A JavaScript object literal copied from source code:

{
  name: 'Blue Mug',
  price: 249,
  tags: ['kitchen', 'gift',],
}

becomes strict JSON:

{
  "name": "Blue Mug",
  "price": 249,
  "tags": [
    "kitchen",
    "gift"
  ]
}

What Gets Fixed

  • Unquoted keys get double quotes.
  • Single-quoted strings become double-quoted.
  • Trailing commas after the last item are removed.

What Cannot Be Converted

JSON is data only, so anything that needs code to run has no JSON equivalent: function values, undefined, new Date(), variables, template literals with ${...}, regular expressions and calculated values. Replace those with plain values before converting - dates, for example, as ISO strings like "2026-09-20".

Where This Helps

  • Turning a JavaScript config or mock object into a JSON fixture for tests or an API.
  • Fixing "JSON" produced by an AI assistant or copied from documentation.
  • Moving settings from a JS config file into package.json or a JSON config.

Check the result with the JSON Validator. Going the other way? Use JSON to JavaScript.

Frequently Asked Questions

Unquoted keys, single-quoted strings and trailing commas - common in JavaScript object literals and config snippets.

No. JSON only holds data, and values that need code to run cannot be converted.

JSON parsers in every language expect double-quoted keys and strings and no trailing commas. Strict JSON works everywhere.
Share this tool: