Wernzi Tools Guide
What Is JSON and How to Format It
JSON is the standard way apps exchange data on the web. Learn what JSON is, how its syntax works, and how to format, validate and minify it.
JSON — short for JavaScript Object Notation — is the most common format for exchanging data between a web browser and a server. Almost every API you use returns JSON, every JavaScript app reads it, and most config files are written in it. If you work with the web, you will meet JSON daily.
The good news is that JSON is deliberately simple. It has only a handful of rules, and once you learn them you can read and write it fluently. This guide explains the syntax, shows common mistakes, and walks through formatting, validating and minifying JSON.
The building blocks of JSON
A JSON document is built from just six kinds of values: objects, arrays, strings, numbers, booleans and null. An object is a set of key-value pairs wrapped in curly braces, like {"name": "Ada", "age": 36}. An array is an ordered list in square brackets, like ["red", "green", "blue"]. Strings must use double quotes, numbers are written plainly, and the only boolean values are true and false.
Values can nest as deeply as you need. An object can contain arrays, arrays can contain objects, and so on. This nesting is what makes JSON powerful: a single document can describe a user, their orders, and every item in each order, all in one readable structure.
{
"name": "Ada Lovelace",
"roles": ["mathematician", "programmer"],
"active": true,
"followers": 128400,
"address": {
"city": "London",
"country": "UK"
}
}Common JSON mistakes
Most JSON errors come from a small set of habits borrowed from other languages. The single most common mistake is using single quotes around strings — JSON only accepts double quotes. Trailing commas are another frequent problem: {"a": 1,} is invalid in JSON even though JavaScript allows it. Comments are not supported either, so a // note inside a JSON file will break parsing.
Unquoted keys are also invalid. In JavaScript you can write {name: "Ada"}, but in JSON the key must be quoted: {"name": "Ada"}. Finally, watch out for undefined and functions — JSON has no way to represent them, so they are silently dropped when JavaScript converts an object with JSON.stringify.
- Use double quotes for all strings and keys — never single quotes.
- No trailing commas after the last item in an object or array.
- No comments, no undefined, no functions.
- Numbers cannot have leading zeros: 01 is invalid, use 1.
Formatting: pretty-printing JSON
JSON from an API usually arrives minified — all on one line with no spaces. That is efficient for machines but painful for humans. Pretty-printing (also called formatting or beautifying) re-indents the document so each key sits on its own line, making the structure visible at a glance. Most developers use two-space indentation; four spaces is also common.
Formatting never changes the data, only the whitespace, so it is completely safe. When you are done editing, you can minify the JSON again to shrink it for transmission. A good JSON formatter also validates the document as it formats, pointing at the exact line and character where a syntax error sits.
Validating JSON before you ship it
A single misplaced comma can take down an API request or crash an app at startup, so validate JSON before you use it. Paste the document into a JSON validator or formatter: it will either confirm the document is valid or report the first error with its position. Fix errors one at a time from the top, because a parser often reports only the first problem it finds and later errors may disappear once the first is fixed.
If you generate JSON in code, prefer your language's built-in JSON library over hand-building strings. Hand-built JSON is where escaping bugs live — a stray quote inside a string value is one of the hardest bugs to spot by eye.
JSON vs YAML vs XML
JSON is not the only data format, but it is the default on the web for good reasons. Compared with XML it is far less verbose — no closing tags, no attributes — which makes it quicker to read and smaller to send. Compared with YAML it is stricter: YAML is more forgiving to write but its indentation rules and implicit typing cause subtle bugs, and every parser handles edge cases slightly differently.
Use JSON for APIs and data exchange, YAML for human-edited configuration, and XML mainly when a system you integrate with requires it. When you need to move data between formats, a converter tool can translate JSON to YAML, XML or CSV in one step.
From API response to readable data: a step-by-step workflow
Here is a workflow you will use constantly. You call an API and get back a single line of minified JSON — hundreds of characters with no line breaks. First, paste it into a JSON formatter: the tool re-indents it and, if the document is broken, points at the exact line and column of the first error. Fix that error and re-format; repeat until the document validates.
With the document readable, find the field you need — most formatters let you collapse sections, so you can fold away the parts you do not care about and focus on one object at a time. Edit a value directly in the formatted view, then check the document still validates. Finally, minify the JSON again before you send it back: the smaller payload is faster to transmit, and since formatting is lossless, nothing about the data has changed. If the API expects a different format, convert the finished JSON to YAML or XML in one step instead of rewriting it by hand.
Try it yourself
Put what you just read into practice with these free tools — no sign-up needed.
Keep learning
- How to Generate a Strong Password — 6 min read
- Base64 Encoding Explained — 5 min read
- What Is a UUID and When to Use It — 5 min read