oktools
Security
Data
API
Converters
Images
Generators
oktools
Security expand_more
password
Password Generator
Generate strong random passwords.
lock
Hash Generator
Generate MD5, SHA-1, SHA-256, SHA-512 hashes.
verified_user
JWT Decoder
Decode and inspect JSON Web Tokens.
workspace_premium
SSL Certificate & CSR Decoder
Decode X.509 certificates, chains and CSRs.
Data expand_more
code
JSON Formatter & Validator
Format and validate JSON.
database
SQL Formatter & Beautifier
Format and minify SQL queries.
difference
JSON Compare (Diff)
Compare two JSON documents.
regular_expression
Regex Tester & Explainer
Test regular expressions and see what they do.
event_repeat
Cron Expression Parser
Decode cron expressions and preview run times.
compare_arrows
Text Diff & Compare
Compare two texts line by line.
API expand_more
api
OpenAPI & Swagger Validator
Validate OpenAPI specs and inspect endpoints.
send
Online API Client
Send HTTP requests like Postman, in your browser.
rule
JSON Schema Validator
Validate JSON against a schema, or generate one.
dataset
Mock Data Generator
Fake JSON data from a schema or an example.
lan
HAR File Viewer
Inspect and sanitise browser HAR files.
pin
HTTP Status Codes
Every HTTP status code, explained.
Converters expand_more
code
Base64 Encoder/Decoder
Encode and decode Base64 text/files.
link
URL Encoder/Decoder
Encode URLs and query parameters.
access_time
Unix Timestamp Converter
Convert Unix timestamps to readable dates.
swap_horiz
CSV ↔ JSON Converter
Convert between CSV and JSON.
data_object
JSON ↔ YAML ↔ TOML Converter
Convert between JSON, YAML and TOML.
tag
Number Base Converter
Convert binary, octal, decimal and hex.
palette
Color Converter & Contrast Checker
Convert HEX, RGB, HSL, OKLCH and check WCAG contrast.
straighten
Unit Converter
Convert kg to lbs, cm to inches, miles to km and more.
public
Time Zone Converter
Convert times between time zones and cities.
Images expand_more
photo_size_select_large
Image Compressor & Converter
Compress, resize and convert images.
crop
Image Cropper & Resizer
Crop, rotate and resize images to exact sizes
web_asset
Favicon Generator
Make favicon.ico, PNG, SVG and manifest icons from an image or text
image_search
EXIF Viewer & Remover
View and strip photo metadata and GPS location
Generators expand_more
credit_card
Credit Card Number Generator (test numbers only)
Generate valid-format test card numbers (non-functional).
format_list_numbered
UUID Generator
Generate UUID/GUID values.
pin
SSN Generator
Generate fake Social Security Numbers with names.
text_fields
Lorem Ipsum Generator
Generate placeholder text.
qr_code_2
QR Code Generator
Create QR codes for links, Wi-Fi, contacts and more.
Home->Data->JSON Formatter & Validator
code

JSON Formatter & Validator

Paste JSON to beautify it with a pretty print at the indent you choose, or minify it to a single line for a request body. The JSON validator lints the text as you type and names the line and column where parsing stopped. Everything runs in your browser; nothing is uploaded.

Format:
input

How it works

The input box is parsed with the browser’s own JSON.parse every time it changes, once a leading byte-order mark has been removed, and the value that comes back is printed again with JSON.stringify: at two spaces, four spaces or a tab in Pretty mode, or with no whitespace at all in Minify. Sort keys rebuilds every object with its keys in code-unit order before printing, at every depth, and leaves arrays as they are. The output follows the input as you type, which is why Validate only confirms in words what the formatted output already shows — if there is output, the document parsed.

When parsing fails, the message is the parser’s own. Chrome and Edge report the character offset where parsing stopped, which is turned into a line and column counted on the text as it appears on screen; Firefox already names both, so nothing is appended. Before the parser is quoted, the text outside strings is scanned for whitespace JSON does not allow, such as a no-break space or a zero-width space, and when the first such character is where parsing broke, the error names it with its Unicode code point instead. Replace with regular spaces then swaps them for ordinary spaces or line feeds, without touching the inside of any string.

Once a document parses, the raw text is scanned for integer literals of sixteen or more digits outside strings. Any beyond 9007199254740991 has already been rounded by the parser, so a warning under the output says how many there are rather than letting the rounded value pass unnoticed. Use output as input moves the formatted text back into the input box, so further edits start from the clean copy, and Clear All empties both boxes while keeping the format, indent and sort choices.

Examples

Pretty-print a minified API response

Each nesting level steps in by the chosen indent and every array item gets a line of its own. The null and the true come through as the literals they are, not as strings, and the key order is kept.

Input
{"id":42,"name":"Ada Lovelace","roles":["admin","ops"],"active":true,"manager":null}
Output
{
  "id": 42,
  "name": "Ada Lovelace",
  "roles": [
    "admin",
    "ops"
  ],
  "active": true,
  "manager": null
}

Minify a document for a request body

Every space and line break between tokens is dropped, while the space inside "SELECT 1" stays, because whitespace inside a string is data. The indent selector is disabled while Minify is on, since there is nothing to indent.

Input
{
  "query": "SELECT 1",
  "params": [],
  "timeout": 30
}
Output
{"query":"SELECT 1","params":[],"timeout":30}

Find the trailing comma in a config file

The comma after true leaves the parser expecting another key, and the closing brace on line 4 is where it gives up. This is Chrome’s wording; Firefox phrases it differently but points at the same line and column.

Input
{
  "port": 8080,
  "debug": true,
}
Error
Expected double-quoted property name in JSON at position 35 (line 4 column 1)

Name an invisible character pasted from a wiki

The two indentation characters on line 2 are no-break spaces, which look exactly like spaces. Chrome would report an unexpected token at that position; the error here names the character instead, and Replace with regular spaces fixes it in one click.

Input
{
  "name": "Ada"
}
Error
Invisible no-break space (U+00A0) at line 2, column 1. Outside strings, JSON allows only ordinary spaces, tabs and line breaks.

Supported formats

  • Strict JSON, as RFC 8259 defines itExactly what JSON.parse accepts: double-quoted keys and strings, no comments, no trailing commas, no single quotes and no NaN or Infinity. The document may be an object, an array or a single value — null on its own is valid.
  • Text as people paste itA leading byte-order mark is ignored and Windows line endings are fine. A no-break space, zero-width space, line separator or similar character outside a string — the usual residue of Confluence, Slack, Word or a terminal — is reported by name and code point rather than as an unexpected token.
  • Three pretty layouts and one minifiedPretty at 2 spaces, 4 spaces or a tab, in JSON.stringify’s layout: one array item per line, empty arrays and objects kept as [] and {}. Minify writes one line with no whitespace between tokens.
  • Key sorting by code unitSort keys orders every object by UTF-16 code unit, so capital letters come before lower-case ones — Alpha, alpha, zeta — and the rule applies at every depth. Array order is never changed, in either mode.

Use cases

  • Read a minified response from the network tabPaste the body of a fetch, axios or curl call and see its structure with one field per line, then copy the formatted version into a bug report or a fixture file.
  • Check a config file before committing itpackage.json, composer.json, a Postman collection, an AWS IAM policy or a Kubernetes manifest written in JSON: the line and column point at the stray comma or missing quote that a deploy would otherwise reject.
  • Shrink a payload for a curl -d body or an environment variableMinify turns a readable document into the single line that fits in a shell argument, a .env value or a query-string parameter.
  • Normalise two documents before a diffFormat both with Sort keys on and the same indent, then compare them in Text Compare — or paste them straight into JSON Diff & Compare, which ignores key order on its own.

Limitations

  • Not JSON5 or JSONCComments, trailing commas, single quotes and unquoted keys are rejected, so tsconfig.json, .vscode/settings.json and other files with comments fail at the first one. Strip the comments first, or format those in your editor.
  • Syntax only, not meaningIt says whether the text is JSON, not whether it is the right JSON. For required fields, types, enums and formats, run the document through the JSON Schema Validator.
  • The error location depends on the browserChrome, Edge and Firefox report where parsing stopped, so a line and column can be shown. Safari’s parser gives a message without a position, and there the error has nothing to locate it with.
  • One document at a timeNewline-delimited JSON or several objects pasted one after another fail at the start of the second value. Split such a file and format one record at a time.
  • Plain text out, no treeThe output is a text area: there is no collapsible tree, no path lookup and no search within the result. For a collapsible tree, paste the document on both sides of JSON Diff & Compare.

Related tools

differenceJSON Compare (Diff)Compare two JSON documents.arrow_forwardruleJSON Schema ValidatorValidate JSON against a schema, or generate one.arrow_forwarddata_objectJSON ↔ YAML ↔ TOML ConverterConvert between JSON, YAML and TOML.arrow_forward

menu_bookFurther reading: JSON vs YAML vs TOML: Which Config Format Should You Use?

Frequently asked questions

How do I format or beautify JSON?

Paste the JSON into the input box and it is re-indented as you type, with nesting laid out one level per step so you can see the structure. Minify collapses it back to a single line with no whitespace, which is the form you want in a request body or a config value. Validate confirms the document in a message, in case you want the explicit answer rather than the formatted output.

Can I change the indentation or sort the keys?

Yes. Pretty output can be indented with two spaces, four spaces or a tab, and Sort keys orders every object’s keys alphabetically at every depth, which makes two documents with the same content line up for a diff. Arrays are never reordered, since in JSON their order is part of the data.

Why is my JSON invalid?

Almost always one of five things: a trailing comma after the last item, single quotes instead of double quotes, unquoted object keys, a comment, or a stray NaN, undefined or Infinity. All are legal JavaScript and none are legal JSON. Text pasted from a web page, a wiki or a chat app can also carry invisible characters such as a no-break space, which JSON does not accept outside strings; the error names the character and Replace with regular spaces swaps them out. The error shown is the browser’s own parser message, with the line and column added whenever the browser reports where it gave up, so start there and work outwards.

What is the difference between formatting and validating?

Validating answers whether the text is JSON at all; formatting changes how it is laid out. They happen together here, because a parser has to read the whole document before it can re-print it — if you get formatted output, the document was valid by definition.

Does formatting change my data?

Not the values, with the exceptions every JavaScript-based formatter shares. Numbers are re-printed in their shortest form, so 1.0 comes out as 1 and 1e2 as 100; an integer above 9007199254740991 (2^53 − 1) is rounded, and the tool warns you under the output when the input holds one; a key that appears twice in the same object keeps only its last value; and keys that look like whole numbers are listed first, in numeric order. Keys, strings, booleans and nesting come through exactly as they were.

Can it handle a large JSON file?

A few megabytes is fine on a normal machine, since the work is a single native parse and re-serialise. Very large documents — tens of megabytes — will make the browser tab work hard, because the whole structure has to be held in memory at once; for those, a streaming tool such as jq is the better instrument.

Is my JSON uploaded to a server?

No. The whole tool is JavaScript running in your own browser, so nothing you type or paste is sent over the network, written to a log or attached to an analytics event. You can confirm it by opening the network tab and watching it stay empty while you work.

oktools

Privacy PolicyAbout UsFAQGuidesSuggest a Tool