HCODX / JSON Formatter
100% browser-based · UTF-8 safe · string-aware tolerant mode

JSON Formatter & Validator

Pretty-print, compact, or check JSON in your browser. Tolerant mode strips comments and trailing commas without corrupting URLs or strings. Optional alphabetical key sort and pure-ASCII \uXXXX output for transport-safe payloads.

Drop a JSON file
or click to browse — .json, .txt
Input JSON
Output
Formatting options
Recurses into nested objects inside arrays too.
ASCII mode escapes every non-ASCII character.
Input size
0 B
Output size
0 B
Structure
Status
Ready
Example

From minified blob to readable JSON

Drop in a one-line API response and get back a tidy nested view, ready to read or diff.

Minified input
{"id":42,"name":"Ada","emails":["ada@example.com","ada@analytical.engine"],"address":{"street":"1 Babbage Lane","city":"London"},"active":true,"score":99.5}
Formatted output
{
  "id": 42,
  "name": "Ada",
  "emails": [
    "ada@example.com",
    "ada@analytical.engine"
  ],
  "address": {
    "street": "1 Babbage Lane",
    "city": "London"
  },
  "active": true,
  "score": 99.5
}
Use cases

What you'll actually use this for

JSON shows up everywhere — readable JSON saves time at every step.

API debugging

Paste a curl response, drop nested objects open visually, and find the field you're looking for in seconds.

Diff-friendly output

Sort keys alphabetically and use a stable indent so two JSON files diff cleanly in Code Diff.

Config sanity check

Catch missing commas, mismatched braces, and unquoted keys before deploying — line/column errors point right at the problem.

Transport-safe payloads

Switch the output to ASCII to escape non-Latin characters as \uXXXX — safe for systems that mangle UTF-8.

Cleaning loose JSON

Strip // comments and trailing commas from JSON5-flavoured config without corrupting URLs or string contents.

Minify before sending

Compact JSON to a single line before stuffing it in an HTTP header or a URL parameter where size matters.

Step by step

How to use the formatter

Three buttons cover everything: Format, Minify, Validate.

1

Paste or drop your JSON

Paste into the left editor or drop a file onto the upload area. Empty lines and trailing whitespace are ignored.

2

Pick options

Choose 2- or 4-space indent (or tab), whether to sort keys, and whether to escape non-ASCII characters. Toggle tolerant mode if your input has comments or trailing commas.

3

Click an action

Format pretty-prints, Minify compacts to one line, Validate just reports valid/invalid with a precise line and column for the error.

4

Copy or download

The output editor has its own toolbar — copy to clipboard, save as output.json, or send the result back to the input for another round.

FAQ

Frequently asked questions

Everything worth knowing about JSON.

JSON (JavaScript Object Notation) is a text-based data interchange format. It supports six value types:

  • Object{ "key": value, … }
  • Array[ value, … ]
  • String — Unicode in double quotes
  • Number — integer or floating-point
  • Booleantrue or false
  • Nullnull

Standardized as RFC 8259 and ECMA-404. Used everywhere — APIs, config files, NoSQL databases, package manifests.

No — neither is allowed by the JSON specification.

Many ecosystems extend JSON anyway:

  • JSONC — JSON with comments (used by VS Code's settings.json)
  • JSON5 — JSON with comments, trailing commas, single quotes, unquoted keys
  • HJSON — even looser human-friendly variant

This formatter offers an opt-in tolerant mode that handles JSONC-style comments and trailing commas. The implementation is string-aware — it walks the source character by character, only stripping comments and trailing commas outside of string literals. So URLs containing // and strings containing , } are preserved verbatim.

It rewrites every non-ASCII character as a JSON \uXXXX escape, so the entire output uses only printable ASCII bytes.

The semantics don't change — JSON.parse reads the escapes back as the original character. It's useful when:

  • Embedding JSON in systems that aren't UTF-8 clean (some legacy tools, certain HTTP headers)
  • Pasting JSON into PDFs, spreadsheets, or anything with limited font fallbacks
  • Diffing two files where invisible Unicode can hide

Example: "日本" becomes "日本".

JSON itself doesn't define key order — most parsers preserve insertion order, but the spec doesn't require it.

This tool sorts recursively:

  • Object keys are sorted alphabetically (or reverse).
  • Arrays preserve their order — but each object inside an array is sorted internally.

That makes two functionally-equivalent JSON files produce identical text after sorting, which is what you want for diffing or content-addressing.

The validator reports a line and column derived from the parser's error position, plus the offending line of source with a caret pointing at the column.

Common causes:

  • Missing comma between properties or array items
  • Unquoted object key (e.g. {a: 1})
  • Single-quoted string (JSON requires double quotes)
  • Trailing comma — turn on tolerant mode if you want them allowed
  • Unescaped control character inside a string (raw newline, tab)
  • Number with leading zero (007) or trailing dot (1.)

Limited by browser memory. Tens of megabytes are comfortable; very large files (hundreds of MB) may freeze the browser temporarily. For huge files, stream through a CLI tool — jq is the gold standard.

No. JSON.parse, JSON.stringify, the comment / trailing-comma stripper, and the Unicode escaper all run in your browser. Your data never leaves the page.

About

About JSON formatting

JSON is the lingua franca of the modern web. Every API, every config file, every SaaS export speaks it. Formatting matters for two reasons: readability (humans need to skim it) and diff-ability (build systems and humans need to compare two JSON documents).

What this tool does — and doesn't

  • Format calls JSON.parse on your input and re-emits with JSON.stringify using your chosen indent, recursive sort, and ASCII-escape preferences.
  • Minify calls JSON.parse + JSON.stringify with no indent argument — produces the most compact valid JSON for the same data.
  • Validate calls JSON.parse and reports either valid with a structural summary, or invalid with line + column.
  • Tolerant mode applies a string-aware pre-pass that strips // line and /* block */ comments and trailing commas before the strict parser runs. Strings are inviolate.

Why string-aware preprocessing matters

A naïve regex like /\/\/.*$/gm happily eats the second slash of "https://example.com", breaking valid JSON. A naïve /,\s*}/g eats commas inside strings like "text, }". This tool walks the source one character at a time, tracking whether it's inside a string and whether the previous character was a backslash — so comments are only stripped where comments would actually be, and trailing commas are only stripped before } or ] at the structural level.

Recursive sort, including arrays

Naïve key-sort implementations stop at arrays — they sort the keys of an object but skip array contents, so an object inside an array stays unsorted. This tool recurses through both kinds of containers, so the output is always canonical for diff comparisons.

UTF-8 vs ASCII output

JSON is defined in terms of Unicode codepoints. Modern systems handle UTF-8 transparently — that's the default here. ASCII mode is an explicit opt-in for transport-fragile scenarios: every codepoint outside U+0000..U+007F becomes \uXXXX, with surrogate pairs handled for codepoints above the Basic Multilingual Plane.

What "valid JSON" means precisely

The strict definition: text that JSON.parse accepts. The validator here defers to the engine's parser. Common gotchas — leading zeros, single quotes, comments, trailing commas, unescaped tabs in strings — are all rejected by strict JSON and explained inline when they fail.