Learn how to format, validate, minify, and transform JSON data. Complete guide with examples, common errors, and free online tools to work with JSON.
JSON is the backbone of modern web development. Every API you call, every configuration file you edit, every NoSQL database you query — they all speak JSON. Yet despite its simplicity, developers waste hours tracking down a missing comma or a trailing bracket in a malformed JSON payload.
This guide covers everything you need to work with JSON effectively. From basic formatting and validation to advanced topics like JSON Schema and API workflows, you will leave with practical knowledge you can use immediately.
JSON stands for JavaScript Object Notation. It is a lightweight, text-based data interchange format that is easy for humans to read and write, and easy for machines to parse and generate. Douglas Crockford popularized it in the early 2000s, and it has since become the dominant format for data exchange on the web.
A simple JSON object looks like this:
{
"name": "Alice",
"age": 30,
"email": "alice@example.com",
"isActive": true,
"roles": ["admin", "editor"],
"address": {
"city": "Berlin",
"country": "Germany"
}
}JSON supports six data types:
"hello"42, 3.14true or falsenull[1, 2, 3]{"key": "value"}That is it. No dates, no comments, no functions. This simplicity is both JSON's greatest strength and a source of common mistakes.
Raw JSON from an API response or a minified file often looks like this:
{
"users": [
{ "id": 1, "name": "Alice", "roles": ["admin", "editor"], "settings": { "theme": "dark", "notifications": true } },
{ "id": 2, "name": "Bob", "roles": ["viewer"], "settings": { "theme": "light", "notifications": false } }
]
}Good luck finding a bug in that. A JSON formatter (also called a JSON beautifier or JSON pretty printer) adds proper indentation and line breaks so you can actually read the data:
{
"users": [
{
"id": 1,
"name": "Alice",
"roles": ["admin", "editor"],
"settings": {
"theme": "dark",
"notifications": true
}
},
{
"id": 2,
"name": "Bob",
"roles": ["viewer"],
"settings": {
"theme": "light",
"notifications": false
}
}
]
}Formatted JSON is easier to debug, easier to review in pull requests, and easier to compare with diff tools. Our JSON Formatter handles this instantly — paste your JSON in and get clean, indented output.
Valid JSON must follow strict syntax rules. Unlike JavaScript objects, JSON has no room for flexibility. A single misplaced character makes the entire document invalid.
JSON validation checks whether your data conforms to the JSON specification (ECMA-404 / RFC 8259). A good validator does two things: tells you whether the JSON is valid, and if it is not, tells you exactly where and why it broke.
Here is a quick checklist for valid JSON:
{} or an array [] (though technically any JSON value is valid at the root level per RFC 8259)You can validate any JSON payload instantly using our JSON Validator. It highlights the exact line and character where the error occurs, which saves significant debugging time.
These are the errors developers hit most often. Each one is a syntax error that will cause any JSON parser to reject the document.
This is the single most common JSON error. JavaScript allows trailing commas in arrays and objects. JSON does not.
Invalid:
{
"name": "Alice",
"age": 30
}Valid:
{
"name": "Alice",
"age": 30
}The fix: remove the comma after the last property or element.
JavaScript accepts both single and double quotes. JSON only accepts double quotes.
Invalid:
{
"name": "Alice"
}Valid:
{
"name": "Alice"
}In JavaScript, object keys do not need quotes. In JSON, every key must be a double-quoted string.
Invalid:
{
"name": "Alice",
"age": 30
}Valid:
{
"name": "Alice",
"age": 30
}JSON does not support comments. No //, no /* */, nothing. If you need comments in a configuration file, consider using JSONC (JSON with Comments) which some tools support, or use JSON5.
Invalid:
{
"port": 3000, // default port
"debug": true
}Valid:
{
"port": 3000,
"debug": true,
"_comment": "debug enables verbose logging"
}The _comment field is a common workaround. The data is still valid JSON, and your application simply ignores keys it does not recognize.
Special characters inside strings must be properly escaped. A literal newline or tab inside a JSON string is invalid — you need \n or \t.
Invalid:
{
"path": "C:\new\folder"
}This breaks because \n is interpreted as a newline and \f as a form feed. Escape the backslashes:
Valid:
{
"path": "C:\\new\\folder"
}JSON does not allow leading zeros on numbers (except for 0 itself and decimals like 0.5).
Invalid:
{
"zipcode": 02134,
"count": 007
}Valid:
{
"zipcode": "02134",
"count": 7
}If the leading zero matters (like a zip code), store it as a string instead.
Before JSON took over, XML was the standard format for data exchange. Both formats are still in active use, so understanding the tradeoffs helps you choose wisely.
| Feature | JSON | XML |
|---|---|---|
| Readability | More concise, easier to scan | Verbose, more tags |
| Data types | Strings, numbers, booleans, null, arrays, objects | Everything is text |
| Comments | Not supported | Supported |
| Schema validation | JSON Schema | XSD, DTD |
| Namespaces | Not supported | Supported |
| Attributes | Not supported | Supported |
| Typical use | REST APIs, config files, NoSQL | SOAP APIs, document markup, enterprise systems |
| Parse speed | Faster in most languages | Slower due to complexity |
Here is the same data in both formats:
JSON:
{
"book": {
"title": "The Pragmatic Programmer",
"year": 2019,
"authors": ["David Thomas", "Andrew Hunt"]
}
}XML:
<book>
<title>The Pragmatic Programmer</title>
<year>2019</year>
<authors>
<author>David Thomas</author>
<author>Andrew Hunt</author>
</authors>
</book>For most modern web applications, JSON is the better choice. It is smaller, faster to parse, and natively supported in JavaScript. XML still has advantages for document-centric data, complex schemas, and enterprise systems that rely on SOAP.
Need to convert between the two? Use our JSON to XML converter for instant transformation.
Minification is the opposite of formatting. It strips all unnecessary whitespace, newlines, and indentation to produce the smallest possible valid JSON string. This matters for production environments where every byte counts — especially for API responses, local storage, and network payloads.
A formatted JSON object:
{
"status": "success",
"data": {
"users": 1542,
"active": 891
}
}Minified:
{ "status": "success", "data": { "users": 1542, "active": 891 } }The minified version is 54 characters. The formatted version is 88 characters. That is a 39 percent reduction. On a large JSON response with hundreds of records, the savings add up fast.
Our JSON Minifier compresses your JSON to the smallest valid representation.
Basic JSON validation only checks syntax. JSON Schema goes further — it lets you define the expected structure, data types, required fields, value ranges, and patterns for your JSON data.
Here is a JSON Schema that defines a user object:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["name", "email", "age"],
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 100
},
"email": {
"type": "string",
"format": "email"
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 150
},
"roles": {
"type": "array",
"items": {
"type": "string",
"enum": ["admin", "editor", "viewer"]
},
"uniqueItems": true
}
},
"additionalProperties": false
}This schema enforces that:
name is a string between 1 and 100 charactersemail is a valid email formatage is an integer between 0 and 150roles is an array of unique strings from a predefined setJSON Schema is widely used for API request validation, configuration file validation, form generation, and documentation. Major API frameworks like Express, FastAPI, and Spring Boot all support JSON Schema for input validation.
APIs are where JSON skills matter most. Whether you are building an API or consuming one, you need to handle JSON correctly at every step.
When sending JSON data to an API, set the Content-Type header to application/json and ensure your body is valid JSON:
{
"method": "POST",
"url": "https://api.example.com/users",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer your-token-here"
},
"body": {
"name": "Alice",
"email": "alice@example.com",
"role": "editor"
}
}API responses typically include a status indicator and nested data. Here is a common response pattern:
{
"status": "success",
"data": {
"id": 42,
"name": "Alice",
"createdAt": "2026-03-27T10:30:00Z"
},
"meta": {
"requestId": "req_abc123",
"processingTime": 45
}
}And an error response:
{
"status": "error",
"error": {
"code": "VALIDATION_FAILED",
"message": "Email address is invalid",
"details": [
{
"field": "email",
"message": "Must be a valid email address"
}
]
}
}You can test API endpoints and inspect JSON responses using our API Tester.
When working with large JSON files or responses, keep these practices in mind:
Real-world workflows often require converting JSON to other formats. CSV exports for spreadsheets, XML for legacy systems, YAML for configuration files — these conversions come up constantly.
Our JSON to CSV converter handles the most common transformation. Given a JSON array of objects, it maps keys to column headers and values to rows:
Input:
[
{ "name": "Alice", "age": 30, "city": "Berlin" },
{ "name": "Bob", "age": 25, "city": "London" },
{ "name": "Charlie", "age": 35, "city": "Tokyo" }
]Output (CSV):
name,age,city
Alice,30,Berlin
Bob,25,London
Charlie,35,Tokyo
This is useful for importing data into Excel, Google Sheets, or any tool that expects tabular data.
After years of working with JSON across APIs, configuration systems, and databases, these are the practices that prevent the most bugs:
Use consistent naming conventions. Pick camelCase or snake_case for your keys and stick with it across your entire API. Mixing conventions leads to confusion and bugs.
Always validate input. Never trust JSON from external sources. Validate against a schema before processing. This catches malformed data, injection attempts, and unexpected types.
Use meaningful key names. Keys like d, val, or x save a few bytes but make the data incomprehensible. JSON is designed to be human-readable — take advantage of that.
Handle dates as ISO 8601 strings. JSON has no date type, so use "2026-03-27T10:30:00Z" format. It sorts correctly as a string, it is unambiguous across timezones, and every language has a parser for it.
Avoid deeply nested structures. If your JSON is more than four or five levels deep, consider flattening it. Deep nesting makes both parsing and querying harder.
Keep null semantics clear. Decide whether a missing key and a null value mean the same thing in your application. Document the distinction. In PATCH endpoints, they often mean different things — missing means "do not change" while null means "clear the value."
Here is a summary of the tools that cover every JSON workflow:
Whether you are debugging an API response at midnight or building a data pipeline, having the right JSON tools at hand makes all the difference. Bookmark the ones you use most — you will reach for them more often than you think.