Skip to main content

JSON_PRETTY

Returns a JSON value formatted across several lines with indentation, for reading nested provider fields.

See also:
[SELECT] [JSON] [JSON_EXTRACT]


Syntax​

SELECT JSON_PRETTY(json_value [, indent]) FROM <multipartIdentifier>;

Arguments​

json_value
A JSON string.

indent
Optional. The string used for each level of indentation. Four spaces when omitted.

Return Value(s)​

Returns a JSON string. An argument that is not valid JSON raises an error.


Examples​

Indent with two spaces​

The second argument sets the indentation:

SELECT JSON_PRETTY('{"a":[1,2]}', ' ') AS v;
{
"a": [
1,
2
]
}

Read a nested provider field​

The following query formats the license object of a repository in a GitHub organization:

SELECT name, JSON_PRETTY(license) AS license
FROM github.repos.repos
WHERE org = 'stackql-labs'
AND license IS NOT NULL
LIMIT 1;

For more information, see https://www.sqlite.org/json1.html#jpretty