SQLite 3 reference · JSON Functions
SQLite JSON() Function
Check and minify JSON text: return it without extra whitespace, or raise an error if it isn't valid JSON.
SQLite 3 Since 3.9.0
Syntax
json(X)
Parameters
| Parameter | Description |
|---|---|
X |
JSON text. |
Return value
Minified JSON text.
Examples
SELECT json(' { "name" : "Ada", "tags" : [ 1, 2 ] } ') AS compact;
Output
compact
{"name":"Ada","tags":[1,2]}SELECT json_valid('{"a": 1}') AS good, json_valid('{a: 1}') AS bad;
Output
good | bad 1 | 0
Version history
| Version | Change |
|---|---|
| SQLite 3.9.0 | Added |
| SQLite 3.38.0 | Built in by default; earlier versions needed the JSON1 extension. |
Related
JSON_VALID()· Return 1 if a string is well-formed JSON and 0 if it isn't. Use it in CHECK constraints or before parsing.JSON_PRETTY()· Return JSON formatted with new lines and indentation (4 spaces by default) so it's easy to read.JSON_OBJECT()· Build a JSON object from key and value pairs. SQL NULL becomes JSON null; nested json() values stay JSON.- SQL String Functions · tutorial