dolt
dolt copied to clipboard
jsonpath lookup bug
repro:
CREATE TABLE xy (x bigint primary key, y JSON);
INSERT INTO xy VALUES (0, CAST('{"a": [{"b": 1}, {"c": 2}]}' AS JSON));
select json_value(y, '$.a.b') from xy;
+------------------------+
| json_value(y, '$.a.b') |
+------------------------+
| [1] |
+------------------------+
select json_extract(y, '$.a.b') from xy;
+--------------------------+
| json_extract(y, '$.a.b') |
+--------------------------+
| [1] |
+--------------------------+
We expect the query to return NULL, because the object nested under "a" is an array, not an object with a "b" key. But we return 1 somehow, falling into the first value of the array to access {"b": 1}.
The lookup expression uses jsonpath.JsonPathLookup(jsonData, path.(string)), which is implemented in our jsonpath library here.