public class JPath
extends java.lang.Object
JPath
represents a lightweight JSONParser and allows parsing
based on the JSON structure and a path relative to this structure.
JPath
must be initialized by using compile(JSONObject)
or compile(String)
. In the last case, the delivered String must be a
valid JSON representation. All parsing results are not cached.
Use read(String)
to parse the underlying JSON based on the delivered
path. The following syntax is supported:
JSONArray[i]
, where i
is a positive integer .
Returns the corresponding element within this array.JSONArray[i].Property
, where Property
is a name
of a JSONObject. Returns the value for the addressed JSONObject.JSONArray.Property
, where Property
is a name of
a JSONObject. Returns a list of values for the addressed JSONObject.JSONArray[a=b]
, where a
is a name of a
JSONObject and b
the expected value. Returns a list of elements
for the addressed JSONObject where the expression is fulfilled.{List: [{Id: 1, Name: Item1}, {Id: 2, Name: Item2}, {Id: 3, Name: Item3}]}
JPath.read(String)
would return:
Modifier and Type | Method and Description |
---|---|
static JPath |
compile(org.json.me.JSONObject object)
Creates a new
JPath based on the delivered JSONObject. |
static JPath |
compile(java.lang.String jsonString)
Creates a new
JPath . |
java.util.Vector |
read(java.lang.String path)
Parses the underlying JSONObject and returns a
Vector containing
the result. |
java.lang.String |
readString(java.lang.String path)
Returns the first found result from
read(String) if it's a
String value. |
void |
update(java.lang.Object value,
java.lang.String expression,
boolean overwriteIfExists)
Updates a given value within the underlying JSON at a specific
expression.
|
public java.lang.String readString(java.lang.String path)
read(String)
if it's a
String value.path
- public java.util.Vector read(java.lang.String path) throws java.lang.Exception
Vector
containing
the result. Each Exception
during the parsing will be passed
through to the calling method.
Use {SELF} to get the JSONObject itself.path
- java.lang.Exception
public void update(java.lang.Object value, java.lang.String expression, boolean overwriteIfExists) throws java.lang.Exception
value
- expression
- overwriteIfExists
- java.lang.Exception
public static JPath compile(org.json.me.JSONObject object)
JPath
based on the delivered JSONObject.object
- public static JPath compile(java.lang.String jsonString)
JPath
. The delivered String must be a valid
JSON representation. Delegates to compile(JSONObject)
.jsonString
- java.lang.RuntimeException
- if the delivered String cannot be used to create a JSONObjectcompile(JSONObject)