21.4. Retrieving JSON Keys (json_keys) #

Required privileges: Postgres Pro AXE administrator only. For a full list of stored procedures and privileges, refer to Section 12.1.

Execute the following command on the Postgres Pro AXE server:

  SELECT json_keys(JSON[, path]) ON CONFLICT DO NOTHING;

Where:

  • JSON: The JSON data from which keys must be retrieved.

    You must specify a JSON string literal or a column with JSON data.

  • path: The path to the JSON element from which keys must be retrieved.

    You can use JSONPath (e.g., $.family) or JSON Pointer (e.g., /family). A list of paths can also be specified, in which case a list of keys for each path is returned.

    Optional parameter.

Postgres Pro AXE returns the keys of the JSON data.

Example 21.4. Executing the json_keys Stored Procedure

JSON data in the j column of the example table:

  {
  "family": "anatidae",
  "species": ["duck", "goose", "swan", null]
  }

Retrieving JSON keys:

  SELECT json_keys(j) FROM example;
  [family, species]