dolt icon indicating copy to clipboard operation
dolt copied to clipboard

jsonpath lookup bug

Open max-hoffman opened this issue 2 years ago • 0 comments

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.

max-hoffman avatar Oct 19 '23 18:10 max-hoffman