Export to GitHub

json-path - issue #7

Matching by field on an array produces array of matches of objects


Posted on Oct 28, 2011 by Swift Giraffe

Given JSON like:

{ "foo" : [ { "id": 1 },
{ "id": 2 },
{ "id": 3 } ] }

a JSON-path of "$.foo.id" should not match. But it does, and it produces [1,2,3]. The correct syntax for that result would be "$.foo[*].id"

In particular this causes a problem when the foo array is empty, as an array is still returned.

We use json-path in rest-driver (https://github.com/rest-driver/rest-driver).and it has been a great help for us. But our users are raising bugs due to this behaviour which we can't work around :(

Comment #1

Posted on Oct 28, 2011 by Swift Giraffe

Just to be clear, I think "$.foo.id" should produce null when matched against the json above. This is the behaviour of (what I assume is) the reference JSONpath implementation from here: http://goessner.net/articles/JsonPath/

Comment #2

Posted on Feb 28, 2012 by Happy Dog

Comment deleted

Comment #3

Posted on Mar 1, 2012 by Happy Dog

This will be in the next release.

Status: Fixed

Labels:
Type-Defect Priority-Medium