1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Merge pull request #234 from erosb/master

fixing stleary/JSON-Java#233
This commit is contained in:
Sean Leary 2016-05-20 21:03:06 -05:00
commit b2bde1f468
2 changed files with 34 additions and 0 deletions

View file

@ -982,6 +982,23 @@ public class JSONArray implements Iterable<Object> {
public Object query(String jsonPointer) {
return new JSONPointer(jsonPointer).queryFrom(this);
}
/**
* Queries and returns a value from this object using {@code jsonPointer}, or
* returns null if the query fails due to a missing key.
*
* @param jsonPointer the string representation of the JSON pointer
* @return the queried value or {@code null}
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
*/
public Object optQuery(String jsonPointer) {
JSONPointer pointer = new JSONPointer(jsonPointer);
try {
return pointer.queryFrom(this);
} catch (JSONPointerException e) {
return null;
}
}
/**
* Remove an index and close the hole.