JSON Syntax Changer

Pretty-prints valid JSON with 2-space indentation, but unquotes any object key that's a valid JavaScript identifier (matches /^[A-Za-z_$][A-Za-z0-9_$]*$/), leaving other keys double-quoted. String values always stay double-quoted; this tool only relaxes key quoting, never value quote style. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

Overview

Introduction

Valid JSON requires every object key to be a double-quoted string, but that's stricter than JavaScript itself needs: a plain object literal in JS source can use unquoted identifier keys.

This tool bridges that gap, taking valid JSON and relaxing its key syntax to match how a human would actually write an object literal by hand.

What Is JSON Syntax Changer?

A syntax relaxer that parses valid JSON, then re-serializes it with a custom recursive printer that checks each key against a JS-identifier regex before deciding whether to quote it.

It's the JSON-to-JS-literal counterpart to how JSON5 and hand-written JS object literals allow bare identifier keys where JSON strictly requires quotes.

How JSON Syntax Changer Works

The tool parses the input with JSON.parse, then recursively rebuilds the output text: for each object key, it tests /^[A-Za-z_$][A-Za-z0-9_$]*$/ and emits the bare key if it matches, or JSON.stringify(key) otherwise.

Every value, scalar or nested, is rendered the same way JSON.stringify would render it, only the key-quoting decision differs from a plain JSON.stringify(value, null, 2) call.

When To Use JSON Syntax Changer

Use it when pasting a JSON sample into JavaScript or TypeScript source code and you want it to look like idiomatic hand-written object literal syntax.

It's also handy for generating config objects, mock data, or test fixtures directly from a JSON example.

Features

Advantages

  • Produces syntax that pastes cleanly into .js/.ts source as a valid object literal.
  • Correctly falls back to quoted keys for anything that isn't a valid bare identifier, so the result is never syntactically broken.
  • Leaves string values untouched, avoiding any ambiguity about quote style for the values themselves.

Limitations

  • The output is not valid JSON and will fail if fed into a JSON.parse call or a strict JSON validator.
  • It doesn't attempt any further JS-specific relaxations (like trailing commas or single-quoted values); it strictly only unquotes valid-identifier keys.

Examples

Unquoting identifier keys

Input

{"name":"Ada","active":true,"2fa":false}

Output

{
  name: "Ada",
  active: true,
  "2fa": false
}

name and active are valid identifiers and get unquoted, while 2fa starts with a digit and stays double-quoted.

Best Practices & Notes

Best Practices

  • Use this specifically when the destination is JS/TS source code, not another JSON-consuming system.
  • If you need single-quoted string values too (a common JS style), follow up with JSON Single Quote Converter.
  • Double-check any key containing hyphens, spaces, or leading digits, since those correctly stay quoted and can't be accessed with dot notation in JS anyway.

Developer Notes

The IDENTIFIER_KEY regex intentionally mirrors JavaScript's own identifier grammar (letter/underscore/dollar start, alphanumeric/underscore/dollar continuation) rather than a looser "no spaces" heuristic, so a key that passes the check is guaranteed to also work as dot-notation property access (obj.key), not just as a valid object literal key.

JSON Syntax Changer Use Cases

  • Converting a JSON API response sample into a JS/TS object literal for test fixtures or mock data
  • Cleaning up JSON before pasting it into application source code as a config object
  • Generating idiomatic-looking JS object literals from JSON without hand-editing every key

Common Mistakes

  • Feeding the output back into a JSON parser and being surprised it fails; the output is intentionally not valid JSON.
  • Assuming hyphenated or space-containing keys get unquoted; they correctly stay quoted since they aren't valid JS identifiers.

Tips

  • Combine with JSON Single Quote Converter if your project's style also prefers single-quoted string values.
  • Use Fix JSON Quotes to go the other direction, repairing relaxed JS-style syntax back into strict JSON.

References

Frequently Asked Questions