diff --git a/JSONArray.java b/JSONArray.java index 7aaa611..f338a2d 100644 --- a/JSONArray.java +++ b/JSONArray.java @@ -30,7 +30,11 @@ import java.io.Writer; import java.lang.reflect.Array; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * A JSONArray is an ordered sequence of values. Its external text form is a @@ -955,6 +959,10 @@ public class JSONArray implements Iterable { } return this; } + + public Object query(String jsonPointer) { + return new JSONPointer(jsonPointer).queryFrom(this); + } /** * Remove an index and close the hole. diff --git a/JSONObject.java b/JSONObject.java index 852358b..ab113f3 100644 --- a/JSONObject.java +++ b/JSONObject.java @@ -32,8 +32,15 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.*; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; import java.util.Map.Entry; +import java.util.ResourceBundle; +import java.util.Set; /** * A JSONObject is an unordered collection of name/value pairs. Its external @@ -1330,6 +1337,10 @@ public class JSONObject { } return this; } + + public Object query(String jsonPointer) { + return new JSONPointer(jsonPointer).queryFrom(this); + } /** * Produce a string in double quotes with backslash sequences in all the diff --git a/JSONPointer.java b/JSONPointer.java index 275c036..e5bc125 100644 --- a/JSONPointer.java +++ b/JSONPointer.java @@ -44,7 +44,7 @@ public class JSONPointer { .replace("\\\\", "\\"); } - public Object queryFrom(JSONObject document) { + public Object queryFrom(Object document) { if (refTokens.isEmpty()) { return document; }