How to Format and Validate JSON: A Start-to-Finish Guide

Published November 9, 2026 · 7 min read · Developer Tools

Last updated: November 9, 2026

JSON Formatter

Paste raw JSON and instantly format or minify it with error highlighting.

Try It Free →

JSON is everywhere. It powers REST APIs, config files, database exports, webhooks, and more. But a single misplaced comma or an unquoted key can make an entire payload fail silently or throw a cryptic parse error. This guide covers everything you need to go from a raw, broken JSON blob to a clean, validated, usable structure.

Last updated: July 2026

What Valid JSON Actually Requires

Before you can format JSON, you need to understand what the spec actually demands. Many developers learn JSON through osmosis and pick up subtle misconceptions that cause real bugs later.

  • Keys must be double-quoted strings. Single quotes are not valid. {'name': 'Alice'} is JavaScript object notation, not JSON.
  • No trailing commas. A comma after the last item in an array or object is invalid JSON, even though most JavaScript engines accept it.
  • No comments. JSON does not support // comments or /* block comments */. If you see them in a config file, it is a JSON superset like JSONC, not standard JSON.
  • Strings must use escape sequences for special characters. Newlines become \n, tabs become \t, and quotes inside strings become \".
  • Numbers cannot have leading zeros. 007 is invalid. Use 7.
  • The root must be an object or array. A bare string or number at the top level is not valid JSON.

Knowing these rules in advance saves you from chasing parse errors that have nothing to do with your logic.

Step 1: Paste and Format Your JSON

The first thing to do with any raw JSON is run it through a formatter. A formatter does two things: it pretty-prints the structure with consistent indentation, and it surfaces syntax errors so you know exactly what to fix.

Open the JSON Formatter on EveryFreeTool and paste your raw payload. If the JSON is valid, you will see a color-coded, indented version immediately. If there is a syntax error, the tool highlights the problem line and describes the issue. This is far faster than reading a raw minified blob and counting brackets by hand.

Common formatting errors and how to fix them

  1. Unexpected token at position X. This almost always means a missing comma, an extra comma, or a stray character. Look at the line before the reported position, not just the reported line itself.
  2. Unterminated string. A string that opens with " but never closes. Check for unescaped quotes inside string values.
  3. Expected colon after property name. A key exists without a corresponding : separator. Often caused by copying data from a spreadsheet or CSV where delimiters differ.
  4. Trailing comma. Remove the comma after the last element in any array or the last property in any object.

Once the formatter shows clean output with no errors, your JSON is syntactically valid. That is the baseline you need before doing anything else with the data.

Step 2: Explore the Structure

If you are working with an unfamiliar API response or a large export, formatted text is still hard to navigate. A tree viewer lets you collapse and expand nested objects and arrays, which makes it much easier to understand the shape of the data before you write any code against it.

Use the JSON Viewer for this step. Paste the formatted JSON and browse the hierarchy visually. You can quickly identify which keys hold arrays, which hold nested objects, and which are simple scalar values. This saves significant time when writing queries or mapping fields in a data pipeline.

Step 3: Validate Against Your Expected Schema

Syntax validity is not the same as semantic validity. A JSON object can be perfectly parseable and still be wrong for your use case because it is missing a required key or has the wrong data type in a field.

Manual schema validation steps to follow:

  • List the keys your application requires and verify each one exists in the formatted output.
  • Check that arrays are actually arrays and not accidentally wrapped in an extra object layer.
  • Confirm numeric fields are numbers, not strings. "count": "42" and "count": 42 look similar but behave very differently in code.
  • Verify that nullable fields that should have a value are not null due to an upstream data issue.

For projects that need automated validation, JSON Schema is the standard approach. You define a schema document that specifies required fields, types, and constraints, then validate payloads against it in your application code or CI pipeline.

Step 4: Transform JSON Into Other Formats

Once your JSON is valid, you often need to convert it into a format that another tool or team member can use.

JSON to CSV

Analysts and finance teams often need flat data they can open in a spreadsheet. If your JSON is an array of flat objects, conversion to CSV is straightforward. Use the JSON to CSV tool to paste your array and download a CSV file. Note that deeply nested objects will either be flattened with dot notation or dropped, depending on the tool, so review the output before sending it to a stakeholder.

JSON to TypeScript

If you are building a TypeScript project, writing interfaces by hand for every API response is tedious and error-prone. Paste the JSON into the JSON to TypeScript converter and get generated interfaces you can drop directly into your codebase. Always review the output because the tool infers types from sample data, and a field that happens to be a number in one response might be a string in another.

Step 5: Minify for Production

Pretty-printed JSON with indentation is human-readable but adds unnecessary bytes when you are sending payloads over a network or storing data at scale. The JSON Formatter tool also handles minification. Switch to the minify option and you get a single-line version of your JSON with all whitespace removed. For large payloads, this can reduce size by 20 to 40 percent, which matters in high-traffic APIs.

Working With JSON in Real-World Scenarios

Debugging a broken API response

Copy the raw response body from your browser's network tab or from a tool like the API Tester. Paste it into the JSON Formatter. If it fails to parse, you now know the server is returning malformed JSON, which is a backend bug, not a frontend one. If it parses but the shape is wrong, you have a schema mismatch to document and report.

Working with config files

Many applications use JSON for configuration. The most common mistake is adding a trailing comma after the last entry when updating a config by hand. Always run config files through the formatter before deploying. This is especially important in CI pipelines where a bad config file can fail a build in a way that is hard to trace without a clear error message.

Cleaning up third-party data exports

Data exports from CRMs, analytics platforms, and databases are often inconsistent. Keys may be missing on some records, values may be empty strings instead of null, and numeric IDs may be returned as strings. Use the viewer to spot these patterns across a sample of records before writing import logic that will fail on edge cases.

Quick Reference: JSON Syntax Rules

  • Objects: {"key": "value"}, keys must be strings in double quotes
  • Arrays: [1, 2, 3] or [{"a": 1}, {"a": 2}]
  • Strings: always double-quoted, special characters escaped
  • Numbers: integers or floats, no leading zeros, no quotes
  • Booleans: lowercase true or false, never quoted
  • Null: lowercase null, never quoted
  • No trailing commas, no comments, no single quotes

Following these rules consistently means you spend less time debugging parse errors and more time building the features that actually matter.

JSON Viewer

Explore nested JSON in a collapsible tree view without writing any code.

Try It Free →

Frequently Asked Questions

Why does my JSON keep failing to parse even though it looks correct?

The most common culprits are trailing commas after the last item in an array or object, single-quoted strings instead of double-quoted ones, and unescaped special characters inside string values. Paste your JSON into a formatter with error highlighting to find the exact position of the problem. Minified JSON is especially hard to read by eye, so always expand it first before debugging.

What is the difference between formatting and validating JSON?

Formatting means adding consistent indentation and whitespace to make JSON human-readable. Validating means checking that the JSON follows correct syntax rules so that parsers can process it without errors. Both steps are useful but distinct. You can have well-formatted JSON that is still invalid if it has a trailing comma, and you can have valid but completely unreadable minified JSON.

Can I add comments to a JSON file?

Standard JSON does not support comments of any kind. If you need comments in a config file, consider JSONC, JSON5, or YAML as alternatives that do support them. Some editors and tools accept comments in JSON config files as an extension, but any standard JSON parser will reject them, so never rely on comments in data that will be parsed programmatically.

How do I convert a JSON array to a spreadsheet?

Use a JSON to CSV converter and paste your array of objects. Each object becomes a row and each unique key becomes a column header. The conversion works cleanly for flat arrays. Nested objects inside each record will either be flattened using dot notation or excluded, depending on the tool, so review the output before distributing the file.

What should I do if an API returns malformed JSON?

First confirm it is actually invalid by pasting the raw response into a JSON formatter. If the tool reports a parse error, the problem is on the server side and you should report it to the API provider with the raw response and the error message. In the meantime, you can sometimes work around it by stripping known bad characters or using a lenient parser, but that is a short-term workaround, not a fix.

Related Tools

🔒 Your data stays in your browser
Need help? Email us