Syntax
Aliases
Parameters
Parameter | Description | Supported input types |
---|---|---|
<json> | The JSON document. | TEXT |
<indentation> | The indentation to use for formatting. | TEXT or INT |
<indentation>
defaults to 4
if omitted.
<indentation>
must be a literal value and cannot be NULL
.
Return Type
TEXT
- If
<json>
isNULL
, the function will returnNULL
. - If
<json>
is malformed, theTRY_
variants returnNULL
whereas the non-TRY_
variants fail with an error message.
Behavior
The function operates in the three modes minify, newlines, and pretty-print, depending on<indentation>
as explained below:
Value of <indentation> | Mode | Description |
---|---|---|
-1 or 'mini' | minify | Produces the most compact representation, omitting any white spaces. |
0 or 'newline' | newlines | Only insert newlines but no spaces for indentation. |
one of 1 , 2 , 4, 8 , or 'pretty' | pretty-print | Pretty-print with newlines and specified indentation. |
<indentation>
of 'pretty'
is identical to 4
.
Examples
For the JSON document indicated by<json_common_example>
below, see our JSON common example.
The returned results are based on the following example.
Example
The following code minifies the JSON document, omitting any white spaces.Example
The following code formats the JSON document with only newlines and without indentation.Example
The following code pretty-prints the JSON document with a default indentation of 4 spaces.Example
The following code attempts to format a malformed JSON document and fails with an error.Example
The following code attempts to format a malformed JSON document and returnsNULL
for the malformed JSON document.