Coginiti menu Coginiti menu

How to Query a JSON Column

You can query a JSON column using various built-in functions and operators to extract and filter data from the JSON object.

Here’s the syntax:

FROM your_table  
WHERE your_json_column ->> 'key' = 'value';

In this example, “->>” is the operator used to extract the value of a key from the JSON column. You can replace ‘key’ and ‘value’ with the specific key-value pair you want in the JSON column.

You can also use other functions like JSON_EXTRACT, JSON_KEYS, and JSON_ARRAYAGG to extract and manipulate JSON data.

For example, if you want to extract all the values of a specific key in a JSON column, you can use the following syntax:

SELECT JSON_EXTRACT(your_json_column, '$.key') AS key_value
FROM your_table;

In this example, “$.key” is the path to the key you want to extract, and the JSON_EXTRACT function extracts the value of the key from the JSON column.