The following is an example showing how to query multiple nested arrays in JSON data in a PostgreSQL database.
Given
CREATE TABLE sample_json (
id serial PRIMARY KEY,
name varchar(64),
json_data json
);
INSERT INTO sample_json (name, json_data)
VALUES
(
'NA',
'
{
"location": "US",
"topLevelArray": [
{
"id": 1,
"secondLevelArray": [
{
"key": "someKey",
"operator": "=",
"value": 10
},
{
"key": "foo",
"operator": ">=",
"value": 5
},
{
"key": "someOtherKey",
"operator": ">",
"value": 647
}
]
},
{
"id":
→ Continue reading “Query nested arrays in PostgreSQL JSON data”