JSON_FORMAT()
All functions > JSON > JSON_FORMAT()
Returns the given JSON expression as a string.
Signatures
Returns: A VARCHAR representation of the JSON value
JSON_FORMAT(expr: JSON) → VARCHAR sql
| Parameter | Type | Required | Description |
|---|---|---|---|
expr | JSON | Yes | The JSON expression to convert to string |
Notes
- Converts JSON values to their string representation; the output is valid JSON text
JSON_PARSE(JSON_FORMAT(x))is the same JSON value asx- The text itself is engine-defined: spacing, object key order and number spelling (
1.50or1.5) follow the backend. DuckDB, Postgres, ClickHouse and serving return the text as it was parsed; BigQuery, Snowflake, Databricks and Trino return a compact text with sorted keys - Do not compare JSON_FORMAT output across backends as text: compare the JSON values, or extract the fields you need
- Primitives are converted to their JSON text (
"hello",true,1)
See also
Examples
Edge cases
FeatureQL
RETURN
-- Convert a JSON object to text. Written compactly with sorted keys, it prints the same on every backend
f1 := JSON_FORMAT(JSON_PARSE('{"age":30,"name":"Alice"}')),
-- Convert a JSON array to text
f2 := JSON_FORMAT(JSON_PARSE('[1,2,3]')),
-- The text parses back to the same value, whatever spacing and key order the backend printed
f3 := JSON_PARSE(JSON_FORMAT(JSON_PARSE('{"name": "Alice", "age": 30}')))
= JSON_PARSE('{"name": "Alice", "age": 30}'),
-- Convert JSON string to string
f4 := JSON_FORMAT(JSON_PARSE('"hello"'))
;Result
| f1 VARCHAR | f2 VARCHAR | f3 BOOLEAN | f4 VARCHAR |
|---|---|---|---|
| {"age":30,"name":"Alice"} | [1,2,3] | true | "hello" |
On this page