⌘+k ctrl+k
1.1.3 (stable)
Search Shortcut cmd + k | ctrl + k
Creating JSON

JSON Creation Functions

The following functions are used to create JSON.

Function Description
to_json(any) Create JSON from a value of any type. Our LIST is converted to a JSON array, and our STRUCT and MAP are converted to a JSON object.
json_quote(any) Alias for to_json.
array_to_json(list) Alias for to_json that only accepts LIST.
row_to_json(list) Alias for to_json that only accepts STRUCT.
json_array([any, ...]) Create a JSON array from any number of values.
json_object([key, value, ...]) Create a JSON object from any number of key, value pairs.
json_merge_patch(json, json) Merge two JSON documents together.

Examples:

SELECT to_json('duck');
"duck"
SELECT to_json([1, 2, 3]);
[1,2,3]
SELECT to_json({duck : 42});
{"duck":42}
SELECT to_json(map(['duck'],[42]));
{"duck":42}
SELECT json_array(42, 'duck', NULL);
[42,"duck",null]
SELECT json_object('duck', 42);
{"duck":42}
SELECT json_merge_patch('{"duck": 42}', '{"goose": 123}');
{"goose":123,"duck":42}