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

jsonpath issue #308

Closed
andysCaplin opened this issue Feb 27, 2021 · 3 comments
Closed

jsonpath issue #308

andysCaplin opened this issue Feb 27, 2021 · 3 comments

Comments

@andysCaplin
Copy link

andysCaplin commented Feb 27, 2021

In our code we allow the application to pass JSON path strings to be applied to our JSON objects.
To test the JSON path string is valid we apply it to an empty JSON object - as shown below

                    try {
                        jsoncons::json result2 = jsoncons::jsonpath::json_query( jsoncons::json::parse("{}"), ptr);
                    } catch (const jsoncons::jsonpath::jsonpath_error& e) {
                        ds_log(event_log, DS_LOG_NOTIFY, "JSON: <%s> couldn't create query with params <%s> error <%s>\n", obj->name, ptr, e.what());
                        jparams->invalid_path = 1;
                    }

We have a unit test that attempts to use the path expression

$[childOrders[0,1]]

Up to jsoncons 0.160.0 this worked ok. But since 0.161.0 I get a failure with this log

<$[childOrders[0,1]]> error <Expected '$' or function expression at line 1 and column 19>

We were on 0.160.0 and I was upgrading to 0.162.1. The issue happens 0.161.0 and every version after.

@danielaparker
Copy link
Owner

danielaparker commented Feb 27, 2021

Allowing a path expression such as childOrders[0,1] inside square brackets notation was a jsoncons extension. Since 0.161.0, this needs to be written as $[@.childOrders[0,1]], see JSONPath extension revisited and the ChangeLog.

@andysCaplin
Copy link
Author

Sorry, as you were writing this I looked at the release notes for 161 - which I should have done first and saw that the path stuff had changed.

@andysCaplin
Copy link
Author

That suggested change works fine. I tested it. Will update our doc. Sorry again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants