Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expression rule for current node and fix getting unique nodes #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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