JSON Formatter & Validator

Format, validate, convert, and generate types from JSON — with auto-unstringify

A CodeMirror-powered JSON editor with line-and-column error reporting. Format or minify, view as a collapsible tree, convert JSON ↔ YAML, and generate TypeScript, Go, Python dataclass / Pydantic, Rust, C#, Java, or Kotlin types from any JSON sample. Pasted a Redis value or escaped log output like "{\"k\":\"v\"}"? We auto-unstringify it for you.

Input JSON

Loading editor…

Formatted JSON

JSON Reference

What JSON is, what it isn't, and the day-to-day gotchas — number precision, single-quote rejection, the JSON-vs-JSON5-vs-JSONC distinction, and parsing in different languages.

The JSON data types

TypeExampleNotes
string"hello"Double quotes only. Single quotes are invalid.
number42 or 3.14 or -1e10IEEE-754 double. No NaN or Infinity. No leading zeros.
booleantrue / falseLowercase only. True / False is invalid.
nullnullLowercase. No undefined in JSON.
array[1, 2, 3]Ordered. No trailing comma.
object{ "key": "value" }Keys must be quoted strings. No trailing comma. No duplicate keys (most parsers).

JSON vs JSON5 vs JSONC vs JSONL

FormatCommentsTrailing commasWhere you see it
JSONNoNoAPIs, config files, the wire format.
JSON5Yes (// and /* */)YesBabel config, some tooling.
JSONC (JSON with comments)Yes (// and /* */)Yes (in practice)tsconfig.json, devcontainer.json, VS Code settings.
JSON Lines (NDJSON / JSONL)NoN/AOne JSON object per line. Log files, big-data streams.

This tool parses strict JSON. For JSONC, strip // and /* */ comments before pasting; for JSON5, also remove trailing commas.

Parsing JSON in different languages

JavaScript / TypeScript

const obj = JSON.parse(text)
const str = JSON.stringify(obj, null, 2)

// Type-safe with zod / valibot:
import { z } from 'zod'
const schema = z.object({ name: z.string() })
const parsed = schema.parse(JSON.parse(text))

Python

import json

obj = json.loads(text)
text = json.dumps(obj, indent=2)

# With Pydantic v2:
from pydantic import BaseModel
class User(BaseModel):
    name: str
user = User.model_validate_json(text)

Go

import "encoding/json"

type User struct {
    Name string `json:"name"`
}

var u User
err := json.Unmarshal(data, &u)
out, err := json.MarshalIndent(u, "", "  ")

Rust (serde)

use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
struct User { name: String }

let u: User = serde_json::from_str(&text)?;
let out = serde_json::to_string_pretty(&u)?;

PHP

$obj = json_decode($text, true);
$text = json_encode($obj, JSON_PRETTY_PRINT);

// With JSON_THROW_ON_ERROR (PHP 7.3+)
$obj = json_decode($text, true, 512,
    JSON_THROW_ON_ERROR);

Bash (jq)

# Pretty-print
echo "$text" | jq .

# Minify
echo "$text" | jq -c .

# Extract a field
echo "$text" | jq -r '.user.name'

Common gotchas

Big numbers lose precision

JSON numbers are IEEE-754 doubles. Integers above 2^53 (≈ 9 quadrillion) round on parse: JSON.parse('9999999999999999') = 10000000000000000. Twitter snowflakes, Discord IDs, blockchain values, and bigint database IDs should travel as JSON strings.

Single quotes are invalid

JSON requires double quotes. If your data uses single quotes, it's a JavaScript object literal or YAML — try the YAML → JSON tab or wrap keys / values in double quotes.

Trailing commas are forbidden

{ "a": 1, } is invalid JSON. Common when copying from JavaScript or JSONC sources — strip the trailing comma or convert to JSON5 first.

JSON has no comments

// like this or /* like this */ will fail to parse. For config files that need comments, use JSONC or YAML.

NaN and Infinity aren't valid JSON

JSON.stringify(NaN) emits null. Some Python libraries emit NaN in non-strict mode — these will fail in strict parsers.

Duplicate keys

Technically allowed by the spec, but the result is parser-dependent (most keep the last value). Avoid them. Our validator surfaces them as warnings.

Double-encoded JSON (the Redis problem)

Storing JSON in a system that itself serialises strings (Redis SET, environment variables, log pipelines) often produces values like "{\"k\":\"v\"}". Our parser detects this and unstringifies automatically — see the “unstringified ×N” badge above the output.

Frequently Asked Questions

Common questions about JSON formatting, validation, type generation, and the JSON-encoded-string auto-unstringify.