public class JSONPointer extends Object
Modifier and Type | Class and Description |
---|---|
static class |
JSONPointer.Builder
This class allows the user to build a JSONPointer in steps, using
exactly one segment in each step.
|
Constructor and Description |
---|
JSONPointer(List<String> refTokens) |
JSONPointer(String pointer)
Pre-parses and initializes a new
JSONPointer instance. |
Modifier and Type | Method and Description |
---|---|
static JSONPointer.Builder |
builder()
Static factory method for
JSONPointer.Builder . |
Object |
queryFrom(Object document)
Evaluates this JSON Pointer on the given
document . |
String |
toString()
Returns a string representing the JSONPointer path value using string
representation
|
String |
toURIFragment()
Returns a string representing the JSONPointer path value using URI
fragment identifier representation
|
public JSONPointer(String pointer)
JSONPointer
instance. If you want to
evaluate the same JSON Pointer on different JSON documents then it is recommended
to keep the JSONPointer
instances due to performance considerations.pointer
- the JSON String or URI Fragment representation of the JSON pointer.IllegalArgumentException
- if pointer
is not a valid JSON pointerpublic static JSONPointer.Builder builder()
JSONPointer.Builder
. Example usage:
JSONPointer pointer = JSONPointer.builder()
.append("obj")
.append("other~key").append("another/key")
.append("\"")
.append(0)
.build();
JSONPointer
instance by chained
JSONPointer.Builder.append(String)
calls.public Object queryFrom(Object document) throws JSONPointerException
document
. The document
is usually a JSONObject
or a JSONArray
instance, but the empty
JSON Pointer (""
) can be evaluated on any JSON values and in such case the
returned value will be document
itself.document
- the JSON document which should be the subject of querying.JSONPointerException
- if an error occurs during evaluationpublic String toString()
public String toURIFragment()