JSON Functions¶
- json_extract_path_text(json text, json_path text)¶
Extracts JSON string from a JSON string based on json path specified and returns JSON string pointed to by JSONPath. Returns null if either argument is null.
Parameters: - json – JSON string
- json_path – JSONpath
Return type: text
Example: select json_extract_path_text('{"test" : {"key" : "tajo"}}','$.test.key'); > tajo
- json_array_get(json_array text, index int4)¶
Returns the element at the specified index into the JSON array. This function returns an element indexed from the end of an array with a negative index, and null if the element at the specified index doesn’t exist.
Parameters: - json_array – String of a JSON array
- index – index
Return type: text
Example: select json_array_get('[100, 200, 300]', 0); > 100 select json_array_get('[100, 200, 300]', -2); > 200
- json_array_contains(json_array text, value any)¶
Determine if the given value exists in the JSON array.
Parameters: - json_array – String of a JSON array
- value – value of any type
Return type: text
Example: select json_array_contains('[100, 200, 300]', 100); > t
- json_array_length(json_array text)¶
Returns the length of json array.
Parameters: json_array – String of a JSON array Return type: int8 Example: select json_array_length('[100, 200, 300]'); > 3