JSON_SCALAR
Example
Section titled “Example”SELECT JSON_SCALAR('{"id": 2, "name": "Alice"}', '$.name') AS result;Output
Section titled “Output”+--------+| result |+--------+| Alice |+--------+Explanation
Section titled “Explanation”The JSON_SCALAR function in the given SQL statement extracts the value associated with the key ‘name’ from the provided JSON object. The output of the function, in this scenario, is ‘Alice’.
Example
Section titled “Example”SELECT jsonb_build_object('key', jsonb_scalar('value')) AS result;Output
Section titled “Output” result---------- {"key": "value"}Explanation
Section titled “Explanation”The jsonb_build_object function in the above example is used to create a JSON object. Inside this function, jsonb_scalar is used to create a JSON scalar value ‘value’. The result is a JSON object with the key ‘key’ and the value ‘value’.