Why format and validate JSON
JSON is the language of modern identity systems. Token claims, key sets, discovery documents, realm exports, client definitions and API responses are all JSON. Machines write it compact, on one line; people need it indented to read it.
Invalid JSON is just as common: a trailing comma left after editing, single quotes from a script, a comment copied from documentation. Most parsers stop with a message that names a position in characters, which is hard to find in a long file. This tool formats valid JSON and points at the exact line and column of the first error.
The JSON rules, briefly
JSON is defined in RFC 8259. It is stricter than JavaScript object syntax.
| Rule | Valid | Invalid |
|---|---|---|
| Strings and keys use double quotes | {"a": "b"} | {'a': 'b'} |
| No trailing commas | [1, 2] | [1, 2,] |
| No comments | {"a": 1} | {"a": 1 // note} |
| No leading zeros | 10, 0.5 | 010, .5 |
| Literals in lower case | true, null | True, NULL |
| Escape control characters in strings | "line\nbreak" | A raw line break inside quotes |
Whitespace between values is free, which is why formatting changes nothing about the data. Key order also carries no meaning: {"a":1,"b":2} and {"b":2,"a":1} are the same object.
What this tool does
- Pretty-prints with 2 spaces, 4 spaces or tabs.
- Minifies to one line with no extra whitespace.
- Sorts keys alphabetically at every level, if you ask.
- Validates strictly against RFC 8259 and reports the first error with its line, column and a pointer under the spot.
- Shows the size in bytes, the number of object members and the nesting depth.
The error position comes from the tool’s own parser, so it is the same in every browser. Built-in parsers word their messages differently from one browser to another.
Invalid JSON at line 3, column 18
Trailing comma before "}". JSON does not allow it.
"enabled": true,
^Step by step
- Paste the JSON into the left box.
- If it is invalid, read the line, column and message, fix the spot, and the result appears.
- Choose pretty-print or minify, and the indent.
- Tick “Sort keys” to make two documents easier to compare.
- Copy the result, or replace the input with it.
JSON in Keycloak work
Realm exports
A realm export holds the realm’s settings, clients, roles, client scopes and more as one JSON document. Exports from the admin console (Realm settings, Action, Partial export) can be large. Formatting with sorted keys makes them readable and lets a text diff show real changes instead of reordering. The realm export analyzer summarizes them, and the realm export diff compares two.
Client definitions
Each client can be exported as JSON from its page in the admin console, and imported again when you create a client. Validating the JSON before an import avoids an unhelpful error.
Admin REST API
The admin REST API takes and returns JSON. Formatting a response makes it readable; validating a request body before you send it saves a round trip. The admin API curl builder writes the requests.
Tokens, keys and discovery
Decoded token payloads, the realm’s certs JSON and its discovery document are all JSON. The dedicated tools read them in more detail: the JWT decoder, the JWKS viewer and the discovery viewer.
Common errors and fixes
| Message | Fix |
|---|---|
| Trailing comma before "}" or "]" | Remove the comma after the last item |
| Expected a key in double quotes | Use "key", not key or 'key' |
| Strings need double quotes | Replace single quotes around values |
| A string contains a raw line break | Write \n instead of a real line break |
| Unexpected "/" | Remove comments; JSON has none |
| Invalid number: leading zeros | Write 10, not 010 |
| Unexpected … after the end of the JSON | Two documents pasted together, or text after the closing brace |
Copying JSON from a chat or a word processor can also replace straight quotes with curly ones. The error then points at the first curly quote.
How validation works
The validator reads the text once from left to right, the way a JSON parser does. At every position it knows what may come next: after { a key or }, after a key a colon, after a value a comma or a closing bracket. The first character that does not fit is the error.
That is why the pointer is reliable but sometimes a little late. A missing comma between two values is only noticed when the second value starts. A missing closing quote is only noticed at the end of the line, where a raw line break appears inside the string.
{
"clientId": "web-app"
"enabled": true
}
# Expected "," or "}", found """ at line 3, column 3Formatting choices
There is no single right style, but some choices make life easier for the people who read and diff your JSON.
| Choice | Good for |
|---|---|
| 2 spaces | Most JavaScript and web projects, and Keycloak exports |
| 4 spaces | Projects whose other code uses 4 spaces |
| Tabs | Teams that want each reader to pick the width |
| Minified | Payloads sent over the network, values inside environment variables |
| Sorted keys | Files kept in version control and compared across environments |
Whatever you choose, apply it consistently. A diff between two exports formatted differently shows every line as changed.
A workflow for comparing two exports
- Paste the first export, tick “Sort keys”, choose 2 spaces and copy the result to a file.
- Do the same with the second export.
- Compare the two files with any diff tool, or with your version control system.
- Ignore generated ids that differ between environments, and focus on settings.
For realm exports in particular, the realm export diff understands the structure and ignores ids for you.
JSON inside other formats
JSON often arrives wrapped in something else, and the wrapper must be removed before validation.
- Inside a JWT: the payload is Base64url-encoded JSON. Decode it with the JWT decoder first.
- Inside a string: JSON stored as a string value has escaped quotes, such as
"{\"a\":1}". Remove the outer quotes and unescape before pasting. - Inside a log line: copy only from the first
{or[to its matching closing bracket. - Inside YAML or a Helm values file: YAML accepts JSON, but YAML-only syntax such as comments must go before validating as JSON.
Limits
The tool checks syntax, not meaning. It cannot tell whether a realm export has the fields Keycloak expects, only whether it is well-formed JSON.
Very large numbers lose precision when parsed by JavaScript, which stores numbers as 64-bit floating point. Integers beyond 2^53 may change when formatted. Identity data rarely has such numbers, but be aware of it when formatting other JSON.
Duplicate keys are valid syntax but the last one wins when parsed, so the formatted output shows only one.
Privacy
Parsing and formatting happen in your browser and nothing is sent to us. Realm exports can contain secrets, such as client secrets or identity provider credentials, so treat them with care wherever you paste them.
Before sharing a realm export, remove secrets with the realm export sanitizer.
Best practices
- Store configuration JSON formatted, with sorted keys, so version control diffs stay small.
- Send JSON minified over the network, where size matters and nobody reads it.
- Validate JSON before importing it into Keycloak or posting it to an API.
- Use UTF-8, which RFC 8259 requires for JSON exchanged between systems.