


/* Schema

{ "type": "object",
  "properties": {
    "value": {"type": "integer"},
    "children": {"type": "array",
                 "items" : {"$ref": "#"},
                 "minItems":2,
                 "maxItems":2}},
  "required": ["value"],
  "additionalProperties": false
}
*/


WITH BTArrays AS
  (SELECT '{ "value":3,
             "children": [ {"value":1,
                            "children": [{"value":0},{"value":2}]}, 
                           {"value":5,
                            "children": [{"value":4},{"value":6}]}
                         ]
           }' :: JSONB AS val)
SELECT jsonb_path_query (val,
                         'strict $')  -- here you paste your query
FROM BTArrays;            -- like this it will return the whole object
