summaryrefslogtreecommitdiff
path: root/documentation
blob: b9a63b5e13874776b24de0e041a1519c2ae276e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
to_json(anyelement) -> json: Encode a value as JSON.
	to_json('string'::TEXT) => '"string"'
	to_json(array['one','two','three',null]::text[]) => '["one","two","three",null]'

from_json(json) -> text: Decode a JSON-encoded value.
	from_json('"string"') => 'string'

json_validate(text) -> boolean: Determine if text is valid JSON.
	json_validate('{key: "value"}') => false
	json_validate('{"key": "value"}') => true

json_get(json, jsonpath text) -> json: Select a single value from a JSON tree using a JSONPath expression.
	json_get('[0,1,2]', '$[1]') => '1'
	json_get('[0,1,2]', '$[100]') => NULL
	json_get('[0,1,2]', '$[*]') => Error

json_set(json, jsonpath text, json) -> json: Set items in a JSON tree that match a JSONPath expression.
	json_set('[0,1,2]', '$[1]', '"x"') => '[0,"x",2]'
	json_set('[0,1,2]', '$[100]', '"x"') => '[0,1,2]'
	json_set('[0,1,2]', '$[*]', '"x"') => '["x","x","x"]'

json_path(json, jsonpath text) -> setof json: Select multiple values from a JSON tree using a JSONPath expression.
	json_path('[0,1,2]', '$[1]') =>
		1
	json_path('[0,1,2]', '$[100]') =>
	json_path('[0,1,2]', '$[*]') =>
		0
		1
		2

json_condense(json) -> json: Re-encodes JSON to form a string with minimal length (mainly removes whitespace).
	json_condense('    {  "key" : "value"}    ') => '{"key":"value"}'
	json_condense($$  "\u266B"  $$) => '"♫"' -- if encoding supports Unicode

json_get_type(json) -> json_type {'null' | 'string' | 'number' | 'bool' | 'object' | 'array'}: Get the type of a <type>json</type> value.
	json_get_type('{"pi": "3.14159", "e": "2.71828"}') => 'object'