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

Complex JSONPath breaking between v12.0.3 and v13.0.1 #2987

Open
lauriekrueger opened this issue Oct 16, 2024 · 1 comment
Open

Complex JSONPath breaking between v12.0.3 and v13.0.1 #2987

lauriekrueger opened this issue Oct 16, 2024 · 1 comment

Comments

@lauriekrueger
Copy link

My complex JSONPath queries that worked with version 12 and below no longer work with version 13+

Source/destination JSON

{
"id": 21,
"name": "Accrual Profiles",
"uniqueKey": "WSAAccrualProfile",
"itemsRetrieveResponseDTOs": [],
"itemsRetrieveResponses": [
{
"itemDataInfo": {
"title": "-TIL",
"key": "-TIL",
"env": null,
"urlparams": "Name=-TIL"
},
"responseObjectNode": {
"@Status": "Success",
"@action": "RetrieveForUpdate",
"WSAAccrualProfile": {
"@name": "-TIL",
"AccrualProfilePolicies": {
"WSAAccrualProfilePolicy": [
{
"@AccrualPolicy": "-Time In Lieu",
"@display": true
},
{
"@AccrualPolicy": "-Time In Lieu 2",
"@display": true
}
]
},
"@PersistentID": "-TIL",
"AccrualProfileBalanceCascadeGroups": {
"WSAAccrualProfileBalanceCascadeGroup": {
"@BalanceCascadeGroup": "-TIL"
}
}
}
}
}
]
}

Expected behavior

I expect to get a IEnumberable from calling SelectTokens(path) with this path

$..['WSAAccrualProfile'][?(@['@name']=='-TIL')]

the above path works in v12.0.3

Actual behavior

null is returned from SelectTokens(path)

Steps to reproduce

    public IEnumerable<JToken> SelectTokens(string xpath)
    {
        return _token.SelectTokens(xpath);
    }
@elgonzo
Copy link

elgonzo commented Oct 17, 2024

null is returned from SelectTokens(path)

It should return an empty enumerable, because the correct result of applying your JsonPath expression to your given json data example should be an empty result. (If you observe SelectTokens returning a null reference instead of an empty enumerable, post a complete self-contained compilable code example that reproduces this behavior. Preferably put it on dotnetfiddle https://dotnetfiddle.net/, so it is certain that it is self-contained.)

If v12.0.3 produces anything other than an empty result for your given json example and JsonPath expression, then the bug is in v12.0.3 (and, if true, then presumably fixed in 13.0.x). Applying your given JsonPath expression to your json example must give an empty result according to the JsonPath specification. Your JsonPath expression looks for children of WSAAccrualProfile which have some @name property. But no child of WSAAccrualProfile has a @name property (only WSAAccrualProfile itself has). Hence why the correct result for the given JsonPath expression must be empty here.

So basically, v13.0.x yielding an empty result is the correct result.

You need to fix your JsonPath expression. One possible JsonPath expression that would select what you want is:

$..[?(@.WSAAccrualProfile['@name'] == '-TIL')].WSAAccrualProfile

It selects any object that has a WSAAccrualProfile child object with a @name property with a "-TIL" value and then selects the WSAAccrualProfile child from that object. (Note that i haven't tested this with Newtonsoft.Json. I am not using Newtonsoft.Json anymore. Its limited JsonPath support is based on the very old Goessner JsonPath spec from 2007, and i haven't verified if the JsonPath i suggested isn't using any features not yet available in that old JsonPath spec. I believe it should be fine but i am not sure, so YMMV... FYI: I verified the correctness of my JsonPath expression using the https://json-everything.net/json-path online JsonPath evaluator, which is based on System.Text.Json and the JsonPath.Net package.)

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