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

using #currentvalueatpath in jsonpath on looping not working #59

Open
rskumargithub opened this issue May 15, 2019 · 1 comment
Open

Comments

@rskumargithub
Copy link

rskumargithub commented May 15, 2019

Hi,

I am trying to filter the array using jsonpath with #currentvalueatpath as below but not working..

Source Data : {
"PhoneTypeToSearch": "iPhone",
"Address": [
{
"City": "NewYork",
"name": "Jim"
},
{
"City": "NewYork",
"name": "John"
}
],
"people": [
{
"name": "Jim",
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888",
"countryPrefix": "34"
},
{
"type": "work",
"number": "012567-8910"
}
]
},
{
"name": "John",
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4562347-8888",
"countryPrefix": "43"
},
{
"type": "home",
"number": "0134523-4567-8910"
}
]
},
{
"name": "John"
}
]
}
Transformer -
{
"Persons": {
"#loop($.people)": {
"Address": "#valueof($.Address[?(@.name== '#currentvalueatpath($.name)')])"
}
}
}

however if I hardcode the filter value like "Address": "#valueof($.Address[?(@.name== 'Jim')])" then its working. but in my case I need pass the name under loop. any idea ?.

@Courela
Copy link
Contributor

Courela commented May 15, 2019

Functions are identified by # at the start of the string/parameter, in this case the # appears somewhere in the middle of the parameter so it won't assume it's a function.
What needs to be done in these cases is to use concat/xconcat function to construct the jsonPath string, since each parameter is checked for function:

{
"Address": "#valueof(#xconcat($.Address[?(@.name==', #currentvalueatpath($.name), ')]))"
}

Unfortunately, in this case there are round brackets in the mix, which causes the parameters for function xconcat to be miscalculated.

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

No branches or pull requests

2 participants