Skip to main content
Formats a JSON document into an easy-to-read, indented string format. This function is useful for debugging or displaying JSON data in a human-readable structure. Tip All of the JSON functions and operators are listed in the navigation and on the overview page.

Syntax

Parameters

  • json_object_expr: The expression that represents the JSON object. The object can be a JSON column, a string containing valid JSON, or a JSON object produced by a JSON constructor function such as PARSE_JSON.

Return value

Returns the formatted JSON document as a string.
  • Returns NULL if the argument is NULL.
  • The returned string includes newlines and spaces for indentation.
  • Object keys are sorted alphabetically in the output.

Examples

Example 1: Format a simple JSON object.
Example 2: Format a JSON array.
Example 3: Format a nested JSON structure.
Example 4: Use with a table column containing JSON data.

Usage notes

  • Indentation: The function adds standard indentation (spaces) and newlines to make the JSON structure visual.
  • Key Sorting: JSON object keys are sorted alphabetically in the output string. This is standard behavior for the underlying JSON processing library (VelocyPack).
  • Null Handling: If the input is SQL NULL, the function returns NULL.
  • Data Types: It supports formatting of standard JSON types including Objects, Arrays, Strings, Numbers, Booleans, and Nulls.