JSON formatter and validator
Format, beautify, pretty print, validate or convert JSON payloads
Paste your input, then choose an action. Validation checks syntax, Pretty makes it readable, and Compact minifies it.
Input JSON
0 lines | 0 charsOutput
0 lines | 0 charsExample
{"name":"api","ports":[80,443],"active":true}{
"name": "api",
"ports": [
80,
443
],
"active": true
}How to use this tool
A quick reference for every feature available in the JSON formatter.
Paste or load your JSON
Type or paste JSON directly into the Input panel. Alternatively, click Upload File to load a .json file from your machine, or use Upload from URL to fetch a JSON endpoint over the network.
Validate syntax
Click Validate to check whether your JSON is syntactically correct. The status bar below the input will turn green on success or red with a precise error message if something is wrong.
Pretty-print for readability
Click Pretty to format the JSON with consistent indentation. Use the Pretty indent control to choose between 1 and 8 spaces per level. The formatted result appears in the Output panel.
Compact for transmission
Click Compact to strip all whitespace and produce the most concise representation. Useful before embedding JSON in an API request body, a config file, or any size-constrained storage.
Chain operations with Swap
Click Swap Output to Input to move the current output back into the input area. This lets you pretty-print, edit, then compact — or run multiple transformations in sequence without copy-pasting.
Convert to XML, YAML, or CSV
Choose a target format from the Convert JSON dropdown — XML, YAML, or CSV — then click Convert. Arrays of objects produce column-based CSV; nested objects produce indented XML or YAML. Copy or download the result with the buttons in the Output panel.
JSON for developers
Practical answers for working with JSON in REST and GraphQL APIs, data pipelines, and everyday engineering.
How should I structure a JSON response for a REST API?
Return a top-level object rather than a bare array, so you can add fields later without breaking clients. Keep a consistent envelope — for example a data field plus optional meta and links for pagination — use one key-casing convention throughout, send the Content-Type: application/json header, and pair the body with the correct HTTP status code instead of signalling failures only inside the payload.
How does JSON work in GraphQL APIs?
GraphQL rides on JSON: the request body is a JSON object with a query string and optional variables, and the response is a JSON object with a data key plus an errors array when something fails. Unlike REST, the client chooses exactly which fields come back, so the response shape mirrors the query — and most GraphQL servers return HTTP 200 even on errors, so inspect the errors array rather than trusting the status code.
What is the best way to represent dates, times, and money in JSON?
JSON has no native date type, so serialise timestamps as ISO 8601 strings in UTC (for example 2026-06-14T09:30:00Z) or as a numeric epoch — and document which you use. ISO 8601 is human-readable and sorts lexicographically; epoch milliseconds are compact and unambiguous. Avoid locale-specific formats, and represent money as integer minor units (cents) or decimal strings to avoid floating-point rounding.
How do I stop large integer IDs from losing precision?
JavaScript parses JSON numbers as IEEE-754 doubles, which represent integers exactly only up to 2^53 − 1. Larger 64-bit values such as database bigints or snowflake IDs silently corrupt beyond that point. Transmit them as strings, or parse with a BigInt-aware library such as json-bigint. Pretty-printing a suspect payload here is a fast way to check whether an ID has already been mangled.
How should a JSON API return errors?
Return a consistent, machine-readable error object: a stable code for programs, a human-readable message, and a details or errors array for field-level validation problems. The application/problem+json format from RFC 9457 (which replaced RFC 7807) is a good ready-made shape. Always set an appropriate 4xx or 5xx status so clients don't have to parse the body just to learn that the call failed.
Should JSON keys use camelCase or snake_case?
Either works — consistency matters far more than the choice. JavaScript, TypeScript, and most GraphQL schemas lean toward camelCase; Python, Ruby, and many SQL-backed APIs use snake_case. Pick one convention per API and enforce it in your serializer, because mixing the two is a common source of bugs and clumsy client code.
What is JSON Lines (NDJSON) and when should I use it?
JSON Lines, also called NDJSON, puts one complete JSON object on each line instead of wrapping everything in a single array. That lets you stream and append records, process huge datasets without loading them entirely into memory, and tail logs in real time — which is why data warehouses like BigQuery and many log pipelines use it. Prefer it whenever one top-level array would be too large to parse at once.
How do I validate JSON against a schema, not just its syntax?
Syntax validation, which is what this tool does, only confirms that a document parses; it does not confirm the right fields and types are present. For that, define a JSON Schema and validate with a library such as Ajv, or describe your API with OpenAPI and generate validators and types from it. Schemas also act as living documentation and enable contract testing between services.
What are the most common JSON security pitfalls?
Never run eval() on JSON — always use JSON.parse. Guard against prototype pollution from crafted __proto__ or constructor keys when you merge parsed objects, cap the accepted payload size to blunt denial-of-service attempts, and validate or escape values before using them in SQL, HTML, or shell contexts. Keep secrets out of any JSON that reaches the client. Because this tool runs entirely in your browser, you can inspect sensitive payloads without sending them anywhere.
How can I reduce JSON payload size in production?
Turn on gzip or Brotli first — JSON's repetitive keys compress extremely well, and that usually beats manual tweaks. Beyond compression, paginate or let clients select fields (sparse fieldsets, or GraphQL field selection), omit null and default values, and shorten needlessly verbose keys. For very hot internal paths where size and speed dominate, consider a binary format instead.
When should I switch from JSON to a binary format like Protocol Buffers?
Keep JSON for public APIs and anything you debug by eye — readability is its main advantage. Switch to Protocol Buffers, Avro, or MessagePack for high-throughput, service-to-service traffic, where payloads are typically several times smaller and parse faster, in exchange for a required schema and bytes humans cannot read. Plenty of systems use both: a binary format internally and JSON at the public edge.
Why does my config with comments or trailing commas fail to parse (JSON5/JSONC)?
Standard JSON allows no comments and no trailing commas, so a tsconfig-style file with // notes is really JSONC, and one with trailing commas or unquoted keys is JSON5 — both need their own parsers and fail strict validation. If the validator here rejects your config file, that mismatch is usually why. Keep the comment-friendly dialects for human-authored config, and use strict JSON for data sent over the wire.
How can I use this tool to debug an API response?
Paste a raw response, upload a .json file, or fetch a URL directly, then click Validate to catch malformed payloads and Pretty to make a minified blob readable. Convert an array of records to CSV to scan it in a spreadsheet, or to YAML or XML when another system needs that format. Everything runs locally in your browser, so it stays safe for production payloads and access tokens.