-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Inconsistent JObject.SelectNode() behavior and feature loss #15505
Comments
Good catch, |
@hyzx86 if your PR fixes both issues, then I need to close my PR then |
Ok , but let me chek first. |
@hishamco , There seems to be a problem with the logic of the remove menu on the main branch, so let me merge your branches |
Or you can merge your branches first, and my branch can solve another problem |
Can you @sarahelsaig / @hyzx86 fix the SelectNode() behavior by using JsonPath.Net ? |
I think so. I will give it a try. |
@sebastienros I've replaced the SelectNode() internals with JsonPath.Net (see PR #15524). |
Describe the bug
I have a few concerns with the new
JObject.SelectNode()
extension method:If you try to use it on a content part's
Content
property, it won't work unless you re-serialize the JSON object first, e.g.:Also you can't chain
SelectNode
calls, the second call will still search from the same position, e.g.:I think when you query a
JsonObject
, it tries to query from its document root instead of the current element. This is unexpected.Finally, I'm not sure if anyone is affected, but after the migration to STJ we have lost full compliant JSONPath query support. The documentation of
JObject.SelectNode()
extension method claims that it searches using "a JSON path", however this is misleading because it's compliant with the JSONPath specification. An example of a query that should work but doesn't (using the same JSON as above):You can verify that the last one should work using the JSONPath Online Evaluator:
Also it works with Newtonsoft:
Expected behavior
SelectNode
should query from the current element.Suggestion
Beyond fixing
JObject.SelectNode
to search from the current node, the documentation should be updated:<remarks>
section explaining what is and what isn't supported by the current implementation.Consider if there is a JSONPath library we can use instead of a homebrew implementation. I haven't used it yet, but JsonPath.Net of the json-everything project might be suitable? It's for STJ, MIT licensed and it seems to be actively maintained.
The text was updated successfully, but these errors were encountered: