json
SQLite 3.9.0 (2015-10-14); JSON5 support added in SQLite 3.38.0 (2022-02-22) as built-in, 3.42.0 for JSON5 reading→ TEXTVerifies that its argument is valid JSON (or JSONB) and returns a minified, canonical RFC-8259 text representation with all unnecessary whitespace removed. Converts JSON5 input to canonical JSON. Throws an error if the input is not well-formed.
Signature
json(json)Parameters
| Parameter | Type | Description |
|---|---|---|
| json | TEXT or BLOB | A well-formed JSON string, JSON5 string, or JSONB blob. Whitespace is stripped and the result is canonical JSON text. |
Examples
Strips whitespace and returns canonical JSON
SELECT json(' { "this" : "is", "a": [ "test" ] } ');'{"this":"is","a":["test"]}'Converts JSON5 unquoted keys to canonical JSON (requires SQLite 3.42.0+)
SELECT json('{x: 42, y: 100}');'{"x":42,"y":100}'Using json() or jsonb() to force a string to be treated as JSON when passing to another function
SELECT json_insert(data, '$.score', jsonb(new_score)) FROM players;Updated JSON with score fieldMinifies an array by removing spaces
SELECT json('[1, 2, 3]');'[1,2,3]'Useful for normalizing stored JSON before comparison or display
SELECT json(profile) FROM users WHERE id = 1;Minified JSON profile stringDevelopers sometimes call json() expecting formatted, readable output. In reality json() minifies the input — it strips all whitespace and returns the most compact canonical form. Passing pretty-printed JSON through json() produces a single dense line with no newlines or indentation.
✓ Instead: Use json_pretty() when you need human-readable, indented JSON output.
When passing a text string as a VALUE argument to functions like json_insert() or json_object(), SQLite treats it as a literal string by default. Wrap it with json() to make SQLite treat it as actual JSON structure: json_object('data', json('[1,2,3]')) produces {"data":[1,2,3]} rather than {"data":"[1,2,3]"}.
SQLite's json() works on TEXT strings (storing JSON as plain text). This differs from PostgreSQL's JSONB type, which is a binary format. In PostgreSQL, casting to JSON with CAST(x AS JSON) or using json_build_object() is the equivalent. SQLite also understands JSON5 extensions (unquoted keys, trailing commas, comments) since 3.42.0, but always outputs canonical RFC-8259.