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

Option for json.path.read to return path instead of value #870

Closed
Merudo opened this issue Nov 3, 2019 · 10 comments
Closed

Option for json.path.read to return path instead of value #870

Merudo opened this issue Nov 3, 2019 · 10 comments
Assignees
Labels
feature Adding functionality that adds value macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) tested This issue has been QA tested by someone other than the developer.

Comments

@Merudo
Copy link
Member

Merudo commented Nov 3, 2019

Is your feature request related to a problem? Please describe.
Sometimes I want to get the indexes of a json.array containing nested elements.

For example, if I have a json array containing Spells as json objects, I'd like to get the indexes of the spells with a specific value in a field instead of the spells themselves.

Describe the solution you'd like
A way to return the paths instead of the values when running a json.path.read statement. A way to do so would be to augment the json.path.read:

json.path.read(json, path, asPath)

where asPath can take the value 1 (to return path) or 0 (to return value).

Additional context
The Jayway library already contains this capability, by using

   Configuration conf = Configuration.builder().options(Option.AS_PATH_LIST).build();
@Merudo
Copy link
Member Author

Merudo commented Nov 4, 2019

More generally, I think it would make sense to add a third parameter, "configuration", that is a json object containing the five Jayway configuration options:

ALWAYS_RETURN_LIST: Makes this implementation more compliant to the Goessner spec.

AS_PATH_LIST: Returns a list of path strings representing the path of the evaluation hits

DEFAULT_PATH_LEAF_TO_NULL: returns null for missing leaf.

REQUIRE_PROPERTIES: Configures JsonPath to require properties defined in path when an indefinite path is evaluated.

SUPPRESS_EXCEPTIONS: Suppress all exceptions when evaluating path.

@Merudo
Copy link
Member Author

Merudo commented Nov 4, 2019

@cwisniew I know you are working on JSON stuff, what do you think of this?

Merudo added a commit to Merudo/maptool that referenced this issue Nov 5, 2019
- Add third parameter "config" to json.path.read, which can take the following values:  ALWAYS_RETURN_LIST, AS_PATH_LIST, DEFAULT_PATH_LEAF_TO_NULL, REQUIRE_PROPERTIES, SUPPRESS_EXCEPTIONS
- Add javadocs
- Close RPTools#870
@Merudo
Copy link
Member Author

Merudo commented Nov 5, 2019

PR #871 implements this.

@Phergus Phergus added deferred Kept for a future version feature Adding functionality that adds value macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) labels Nov 9, 2019
Merudo added a commit to Merudo/maptool that referenced this issue Jan 14, 2020
- Add third parameter "config" to json.path.read, which can take the following values: ALWAYS_RETURN_LIST, AS_PATH_LIST, DEFAULT_PATH_LEAF_TO_NULL, REQUIRE_PROPERTIES, SUPPRESS_EXCEPTIONS
- Close RPTools#870
@Phergus Phergus added documentation needed Missing, out-of-date or bad documentation and removed deferred Kept for a future version labels Jan 14, 2020
@Merudo
Copy link
Member Author

Merudo commented Jan 14, 2020

PR #1112 implements this.

@Merudo
Copy link
Member Author

Merudo commented Jan 15, 2020

Documentation updated: json.path.read

@Phergus Phergus removed the documentation needed Missing, out-of-date or bad documentation label Jan 15, 2020
@Phergus
Copy link
Contributor

Phergus commented Jan 17, 2020

Testing new parameters.

@Phergus
Copy link
Contributor

Phergus commented Jan 17, 2020

Going to need an example of what REQUIRE_PROPERTIES is used for. Didn't see it in the Jayway docs.

@JamzTheMan
Copy link
Member

JamzTheMan commented Jan 17, 2020

https://www.javadoc.io/doc/com.jayway.jsonpath/json-path/2.0.0/com/jayway/jsonpath/Option.html

Doc actually had an example, go figure lol (didn't expect it to be helpful)

Hopefully this it's the same thing at least...

@Phergus
Copy link
Contributor

Phergus commented Jan 17, 2020

What?! Useful examples in a javadoc?

That definitely helps.

@Phergus Phergus added the tested This issue has been QA tested by someone other than the developer. label Jan 17, 2020
@Phergus
Copy link
Contributor

Phergus commented Jan 17, 2020

All config options tested.

@Phergus Phergus closed this as completed Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding functionality that adds value macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) tested This issue has been QA tested by someone other than the developer.
Projects
None yet
Development

No branches or pull requests

3 participants