# JSON Formatter & Validator

> The JSON Formatter & Validator pretty-prints or minifies JSON, points to the exact line and column of any syntax error, shows a collapsible tree, can sort keys, and converts JSON to CSV or YAML (and back) in your browser.

URL: https://atechcraft.com/json-formatter/
Category: Developer Tools
Last updated: 2026-12-01
Author: Abdul Moid Khan, ATechCraft

Runs in your browser. Your data never leaves your device.

## How to use the JSON Formatter & Validator

1. Paste JSON into the input box, or YAML or CSV if you want to convert to JSON.
2. Click Format, Minify or Sort keys. Errors show the line and column.
3. Open the Tree tab to explore nested data.
4. Convert to CSV or YAML if needed, then copy or download the result.

## What is a JSON formatter and validator?

A JSON formatter turns compact or messy JSON into neatly indented text that people can read, and a validator checks that the JSON follows the rules. This tool does both: it pretty-prints with 1, 2 or 4 spaces, minifies to a single line, sorts object keys alphabetically, shows the exact line and column of any syntax error, displays a collapsible tree, and converts between JSON, CSV and YAML.

Everything runs in your browser with the built-in `JSON.parse` engine, so API responses, config files and customer data never leave your device.

## What makes JSON valid?

JSON (JavaScript Object Notation) is defined by [RFC 8259](https://www.rfc-editor.org/rfc/rfc8259) and ECMA-404. It is stricter than JavaScript. These are the mistakes behind most "invalid JSON" errors:

| Mistake | Invalid | Valid |
| --- | --- | --- |
| Trailing comma | `{"a": 1,}` | `{"a": 1}` |
| Single quotes | `{'a': 'x'}` | `{"a": "x"}` |
| Unquoted key | `{a: 1}` | `{"a": 1}` |
| Comments | `{"a": 1 // note}` | Not allowed in JSON |
| `undefined` or `NaN` | `{"a": NaN}` | Use `null` or a number |
| Leading zeros | `{"n": 007}` | `{"n": 7}` |
| Unescaped newline in a string | `"line one` ⏎ `line two"` | `"line one\nline two"` |

When parsing fails, the browser reports a character position. The tool converts that into a line and column so you can jump straight to the problem. Different browsers word their messages differently, but the location is reliable.

## How do JSON to CSV and YAML conversions work?

**JSON → CSV:** the input should be an array of objects (one object per row) or a single object. Nested objects are flattened with dot notation, so `{"address": {"city": "Lahore"}}` becomes a column named `address.city`. Arrays of simple values are joined with semicolons. Values containing commas, quotes or line breaks are quoted following [RFC 4180](https://www.rfc-editor.org/rfc/rfc4180). Columns are the union of all keys, so missing values become empty cells.

**CSV → JSON:** the first row becomes the keys, and every other row becomes an object of strings.

**JSON ⇄ YAML** uses the open-source js-yaml library (MIT), loaded only when you click a YAML button. YAML is popular for configuration files like Docker Compose and GitHub Actions.

## Worked example

Paste this minified API response:

```json
{"user":{"name":"Ayesha","city":"Lahore"},"orders":[{"id":101,"total":2500},{"id":102,"total":1200}],"active":true}
```

**Format** (2 spaces) gives:

```json
{
  "user": {
    "name": "Ayesha",
    "city": "Lahore"
  },
  "orders": [
    { "id": 101, "total": 2500 },
    ...
```

(the real output puts each order field on its own line). **JSON → CSV** on the `orders` array alone gives:

```text
id,total
101,2500
102,1200
```

Now remove the closing `}` and press Format: the tool reports *Invalid JSON at line 1, column 118* (the exact column depends on your browser), pointing at the end where a brace is missing.

## Tips

1. **Sort keys before comparing.** Two JSON files with the same data in a different key order look different line by line. Sort both, then compare them with the [Text Diff Checker](https://atechcraft.com/text-diff/).
2. **Use the tree view** to explore deep API responses without scrolling through hundreds of lines.
3. **Minify for storage, format for humans.** Minified JSON is smaller to send; formatted JSON is easier to review.
4. **Decode tokens first.** If the JSON is inside a JWT, use the [JWT Decoder](https://atechcraft.com/jwt-decoder/); if it is Base64-encoded, use the [Base64 tool](https://atechcraft.com/base64-encoder-decoder/).
5. **Writing structured data for SEO?** The [Schema Markup Generator](https://atechcraft.com/schema-generator/) builds JSON-LD from a form.

## Limitations

- Numbers larger than 2⁵³ (about 9 quadrillion) lose precision in JavaScript, so very long IDs may change when formatted. Keep such IDs as strings.
- Duplicate keys are allowed by the parser but only the last value is kept.
- The tree view shows up to 500 children per level to keep the page fast.
- JSON with comments (JSONC, used by VS Code settings) or JSON5 is not accepted. Remove the comments first.
- CSV export of deeply nested arrays of objects creates many columns (`orders.0.id`, `orders.1.id`); export the inner array instead for a cleaner table.

For quick size savings on CSS or JavaScript instead, use the [Code Minifier](https://atechcraft.com/code-minifier/).

## Frequently asked questions

### Why is my JSON invalid?

The most common causes are trailing commas, single quotes instead of double quotes, unquoted keys and comments. Strict JSON (RFC 8259) allows none of these.

### Is my JSON uploaded?

No. Parsing uses your browser’s built-in JSON engine, so API responses and config files stay on your device.

### How does JSON to CSV work with nested objects?

Nested keys are flattened with dots, such as address.city. Arrays of simple values are joined with a semicolon. The input must be an array of objects or a single object.

### Can it handle large files?

Files of several megabytes format quickly. The tree view is limited for very large data to keep the page responsive.
