Skip to content

Conversation

@lar-dragon
Copy link

Rules with expressions allow select nodes by name and content in Jayway JsonPath implementation. for example:

[
 { "a": { "c": 1, "d": 1 }, "b": { "c": 1, "d": 2 } },
 { "a": { "c": 2, "d": 3 }, "b": { "c": 2, "d": 4 } }
]

rule $..a[?(@.c==2)] selects

[ { "c" : 2, "d" : 3 } ]

This changes add similar behavior and allow getting unique nodes with values by references. The following code becomes valid:

$jsonStore = new JsonStore([
 [ "a"=>[ "c"=>1, "d"=>1 ], "b"=>[ "c"=>1, "d"=>2 ] ],
 [ "a"=>[ "c"=>2, "d"=>3 ], "b"=>[ "c"=>2, "d"=>4 ] ]
]);
// set "d" to 5 only for "a" node witch field "c" equivalent 2
$jsonStore->get('$..a[?(@.c==2)]', true)[0]['d'] = 5;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant