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

Not able to resolve JsonPath when it includes a where condition #318

Open
Meenakshise opened this issue Oct 22, 2022 · 1 comment
Open

Comments

@Meenakshise
Copy link

I have specified this as my condition

conditions: {
all: [{
fact: 'displayMessage',
operator: 'equal',
value: "iphone",
path:"$.childobj.phoneNumbers.[?(@.number=='0123-4567-8888')].type"
}]

And this is the fact -

const facts = { displayMessage: {"childobj" : { "age" : 45 , "phoneNumbers": [
{
"type": "iphone",
"number": "0123-4567-8888"
},
{
"type": "home",
"number": "0123-4567-8910"
}
]} } }

It is not working..
Can you please tell me if this is supported or not?
It is working if i specify this path - $.childobj.phoneNumbers.[0].type where no condition is specified. Whereas in the above path I have specified the condition.

@Meenakshise
Copy link
Author

I think it's because Json-Path always returns the result in the form of an array when we have a where condition in our json-path like this
$.childobj.phoneNumbers.[?(@.number=='0123-4567-8888')].type - the return type of this selection is an array.
But when we don't have a where condition, the result it returns is in the form of a string. We can validate this in the javascript
$.childobj.phoneNumbers.[0].type - the return type of this selection is a string

Hence while matching these values it results in false as the data types are completely different.

So what I did was while deriving the factvalue from the almanac.js file inside the factValue method I just added the below line of code

if(_typeof(pathValue)== 'string' )
return pathValue;
else if(_typeof(pathValue) == 'object')
return pathValue[0];

After this change it is working for me. Can I use this fix to support this or will it break anything else. Please confirm me.

@Meenakshise Meenakshise changed the title Not able to resolve JsonPath specified in the condition Not able to resolve JsonPath when it includes a where condition Oct 25, 2022
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

1 participant