Skip to content

JSON formatter and validator

Pretty-print, minify and validate JSON, with the line and column of any syntax error and a pointer to the spot.

Runs in your browser. Nothing you paste is sent to us.

JSON

A sample client definition for the made-up realm acme is filled in.

Valid JSON

Result

Formatted JSON
{
  "clientId": "web-app",
  "enabled": true,
  "publicClient": true,
  "redirectUris": [
    "https://app.example.com/*"
  ],
  "webOrigins": [
    "https://app.example.com"
  ],
  "standardFlowEnabled": true,
  "attributes": {
    "pkce.code.challenge.method": "S256",
    "post.logout.redirect.uris": "https://app.example.com/"
  },
  "defaultClientScopes": [
    "profile",
    "roles",
    "web-origins"
  ]
}
Size
414 bytesInput 332 bytes
Values
10Object members, counted at every level
Depth
2

How to use it

  1. Paste the JSON.
  2. Choose pretty-print or minify, and the indent.
  3. Sort keys to make two documents easier to compare.
  4. If it is invalid, read the line, column and message.

What to know

The validator follows RFC 8259 strictly: double quotes only, no trailing commas, no comments and no leading zeros. The error position is the same in every browser.

Keycloak realm exports, client definitions from the admin console and token claims are all JSON. Formatting them makes a change easy to spot in a diff.

Sorting keys changes nothing in the data; JSON objects have no order.

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.

RuleValidInvalid
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 zeros10, 0.5010, .5
Literals in lower casetrue, nullTrue, 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.

An error report for a trailing comma
Invalid JSON at line 3, column 18
Trailing comma before "}". JSON does not allow it.

  "enabled": true,
                 ^

Step by step

  1. Paste the JSON into the left box.
  2. If it is invalid, read the line, column and message, fix the spot, and the result appears.
  3. Choose pretty-print or minify, and the indent.
  4. Tick “Sort keys” to make two documents easier to compare.
  5. 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

MessageFix
Trailing comma before "}" or "]"Remove the comma after the last item
Expected a key in double quotesUse "key", not key or 'key'
Strings need double quotesReplace single quotes around values
A string contains a raw line breakWrite \n instead of a real line break
Unexpected "/"Remove comments; JSON has none
Invalid number: leading zerosWrite 10, not 010
Unexpected … after the end of the JSONTwo 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.

A missing comma is reported at the start of the next key
{
  "clientId": "web-app"
  "enabled": true
}
# Expected "," or "}", found """ at line 3, column 3

Formatting choices

There is no single right style, but some choices make life easier for the people who read and diff your JSON.

ChoiceGood for
2 spacesMost JavaScript and web projects, and Keycloak exports
4 spacesProjects whose other code uses 4 spaces
TabsTeams that want each reader to pick the width
MinifiedPayloads sent over the network, values inside environment variables
Sorted keysFiles 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

  1. Paste the first export, tick “Sort keys”, choose 2 spaces and copy the result to a file.
  2. Do the same with the second export.
  3. Compare the two files with any diff tool, or with your version control system.
  4. 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.
Questions

Frequently asked questions

Why is my JSON invalid?

The usual causes are single quotes, a trailing comma, a comment, or an unescaped line break inside a string. The message names which, and the pointer shows where.

Is my JSON sent anywhere?

No. It is checked and formatted in your browser.

Does sorting keys change the data?

No. JSON objects have no order, so a sorted document means exactly the same. Sorting only makes documents easier to read and compare.

Can JSON have comments?

No. RFC 8259 has no comment syntax. Some tools accept comments in variants such as JSONC, but standard JSON parsers reject them.

Why does the pointer sit just after my mistake?

The pointer marks the first character that cannot be valid at that place. A missing comma or quote is only noticed at the next character, so look just before the pointer too. For trailing commas, the pointer marks the comma itself.

How do I format a Keycloak realm export?

Paste the exported file here, choose 2-space indentation and sorted keys, and copy the result. For an overview of what the export contains, use the realm export analyzer.

What is the difference between minify and pretty-print?

Minify removes all whitespace for the smallest size; pretty-print adds line breaks and indentation for reading. The data is the same.

Can it handle very large files?

It runs in your browser, so the limit is your device’s memory. Files of a few megabytes, such as large realm exports, format without trouble on a typical computer.

Why do curly quotes break my JSON?

JSON accepts only the straight double quote. Word processors and some chat apps replace it with curly quotes, which the parser treats as unexpected characters. Replace them with straight quotes and validate again.

Is JSON with duplicate keys valid?

RFC 8259 says names within an object should be unique but does not forbid duplicates. Parsers usually keep the last value, so the formatted output shows only one. Avoid duplicates, because different parsers may disagree.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.