public class JsonPath
extends java.lang.Object
String json = "{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 } ], "bicycle": { "color": "red", "price": 19.95 } } }";A JsonPath can be compiled and used as shown:
JsonPath path = JsonPath.compile("$.store.book[1]");
List<Object> books = path.read(json);
Or:
List<Object> authors = JsonPath.read(json, "$.store.book[*].author")
If the json path returns a single value (is definite):
String author = JsonPath.read(json, "$.store.book[1].author")
Modifier and Type | Method and Description |
---|---|
<T> T |
add(java.lang.Object jsonObject,
java.lang.Object value,
Configuration configuration)
Adds a new value to the Array this path points to in the provided jsonObject
|
static JsonPath |
compile(java.lang.String jsonPath,
Predicate... filters)
Compiles a JsonPath
|
<T> T |
delete(java.lang.Object jsonObject,
Configuration configuration)
Deletes the object this path points to in the provided jsonObject
|
java.lang.String |
getPath()
Returns the string representation of this JsonPath
|
boolean |
isDefinite()
Checks if a path points to a single item or if it potentially returns multiple items
a path is considered not definite if it contains a scan fragment ".."
or an array position fragment that is not based on a single index
definite path examples are:
$store.book
$store.book[1].title
not definite path examples are:
$..book
$.store.book[*]
$.store.book[1,2]
$.store.book[?(@.category = 'fiction')]
|
static boolean |
isPathDefinite(java.lang.String path) |
<T> T |
map(java.lang.Object jsonObject,
MapFunction mapFunction,
Configuration configuration)
Replaces the value on the given path with the result of the
MapFunction . |
static DocumentContext |
parse(java.io.File json)
Parses the given JSON input using the default
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.io.File json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.io.InputStream json)
Parses the given JSON input using the default
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.io.InputStream json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.lang.Object json)
Parses the given JSON input using the default
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.lang.Object json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.lang.String json)
Parses the given JSON input using the default
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.lang.String json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.net.URL json)
Deprecated.
|
static DocumentContext |
parse(java.net.URL json,
Configuration configuration)
Deprecated.
|
<T> T |
put(java.lang.Object jsonObject,
java.lang.String key,
java.lang.Object value,
Configuration configuration)
Adds or updates the Object this path points to in the provided jsonObject with a key with a value
|
<T> T |
read(java.io.File jsonFile)
Applies this JsonPath to the provided json file
|
<T> T |
read(java.io.File jsonFile,
Configuration configuration)
Applies this JsonPath to the provided json file
|
static <T> T |
read(java.io.File jsonFile,
java.lang.String jsonPath,
Predicate... filters)
Creates a new JsonPath and applies it to the provided Json object
|
<T> T |
read(java.io.InputStream jsonInputStream)
Applies this JsonPath to the provided json input stream
|
<T> T |
read(java.io.InputStream jsonInputStream,
Configuration configuration)
Applies this JsonPath to the provided json input stream
|
<T> T |
read(java.io.InputStream jsonInputStream,
java.lang.String charset,
Configuration configuration)
Applies this JsonPath to the provided json input stream
|
static <T> T |
read(java.io.InputStream jsonInputStream,
java.lang.String jsonPath,
Predicate... filters)
Creates a new JsonPath and applies it to the provided Json object
|
<T> T |
read(java.lang.Object jsonObject)
Applies this JsonPath to the provided json document.
|
<T> T |
read(java.lang.Object jsonObject,
Configuration configuration)
Applies this JsonPath to the provided json document.
|
static <T> T |
read(java.lang.Object json,
java.lang.String jsonPath,
Predicate... filters)
Creates a new JsonPath and applies it to the provided Json object
|
<T> T |
read(java.lang.String json)
Applies this JsonPath to the provided json string
|
<T> T |
read(java.lang.String json,
Configuration configuration)
Applies this JsonPath to the provided json string
|
static <T> T |
read(java.lang.String json,
java.lang.String jsonPath,
Predicate... filters)
Creates a new JsonPath and applies it to the provided Json string
|
<T> T |
read(java.net.URL jsonURL)
Applies this JsonPath to the provided json URL
|
static <T> T |
read(java.net.URL jsonURL,
java.lang.String jsonPath,
Predicate... filters)
Deprecated.
|
<T> T |
renameKey(java.lang.Object jsonObject,
java.lang.String oldKeyName,
java.lang.String newKeyName,
Configuration configuration) |
<T> T |
set(java.lang.Object jsonObject,
java.lang.Object newVal,
Configuration configuration)
Set the value this path points to in the provided jsonObject
|
static ParseContext |
using(Configuration configuration)
Creates a
ParseContext that can be used to parse JSON input. |
static ParseContext |
using(JsonProvider provider)
Deprecated.
|
public java.lang.String getPath()
public static boolean isPathDefinite(java.lang.String path)
isDefinite()
public boolean isDefinite()
public <T> T read(java.lang.Object jsonObject)
JsonProvider
T
- expected return typejsonObject
- a container Objectpublic <T> T read(java.lang.Object jsonObject, Configuration configuration)
JsonProvider
T
- expected return typejsonObject
- a container Objectconfiguration
- configuration to usepublic <T> T set(java.lang.Object jsonObject, java.lang.Object newVal, Configuration configuration)
T
- expected return typejsonObject
- a json objectconfiguration
- configuration to usepublic <T> T map(java.lang.Object jsonObject, MapFunction mapFunction, Configuration configuration)
MapFunction
.jsonObject
- a json objectmapFunction
- Converter object to be invokedconfiguration
- configuration to usepublic <T> T delete(java.lang.Object jsonObject, Configuration configuration)
T
- expected return typejsonObject
- a json objectconfiguration
- configuration to usepublic <T> T add(java.lang.Object jsonObject, java.lang.Object value, Configuration configuration)
T
- expected return typejsonObject
- a json objectvalue
- the value to addconfiguration
- configuration to usepublic <T> T put(java.lang.Object jsonObject, java.lang.String key, java.lang.Object value, Configuration configuration)
T
- expected return typejsonObject
- a json objectkey
- the key to add or updatevalue
- the new valueconfiguration
- configuration to usepublic <T> T renameKey(java.lang.Object jsonObject, java.lang.String oldKeyName, java.lang.String newKeyName, Configuration configuration)
public <T> T read(java.lang.String json)
T
- expected return typejson
- a json stringpublic <T> T read(java.lang.String json, Configuration configuration)
T
- expected return typejson
- a json stringconfiguration
- configuration to usepublic <T> T read(java.net.URL jsonURL) throws java.io.IOException
T
- expected return typejsonURL
- url to read fromjava.io.IOException
public <T> T read(java.io.File jsonFile) throws java.io.IOException
T
- expected return typejsonFile
- file to read fromjava.io.IOException
public <T> T read(java.io.File jsonFile, Configuration configuration) throws java.io.IOException
T
- expected return typejsonFile
- file to read fromconfiguration
- configuration to usejava.io.IOException
public <T> T read(java.io.InputStream jsonInputStream) throws java.io.IOException
T
- expected return typejsonInputStream
- input stream to read fromjava.io.IOException
public <T> T read(java.io.InputStream jsonInputStream, Configuration configuration) throws java.io.IOException
T
- expected return typejsonInputStream
- input stream to read fromconfiguration
- configuration to usejava.io.IOException
public <T> T read(java.io.InputStream jsonInputStream, java.lang.String charset, Configuration configuration) throws java.io.IOException
T
- expected return typejsonInputStream
- input stream to read fromconfiguration
- configuration to usejava.io.IOException
public static JsonPath compile(java.lang.String jsonPath, Predicate... filters)
jsonPath
- to compilefilters
- filters to be applied to the filter place holders [?] in the pathpublic static <T> T read(java.lang.Object json, java.lang.String jsonPath, Predicate... filters)
T
- expected return typejson
- a json objectjsonPath
- the json pathfilters
- filters to be applied to the filter place holders [?] in the pathpublic static <T> T read(java.lang.String json, java.lang.String jsonPath, Predicate... filters)
T
- expected return typejson
- a json stringjsonPath
- the json pathfilters
- filters to be applied to the filter place holders [?] in the path@Deprecated public static <T> T read(java.net.URL jsonURL, java.lang.String jsonPath, Predicate... filters) throws java.io.IOException
T
- expected return typejsonURL
- url pointing to json docjsonPath
- the json pathfilters
- filters to be applied to the filter place holders [?] in the pathjava.io.IOException
public static <T> T read(java.io.File jsonFile, java.lang.String jsonPath, Predicate... filters) throws java.io.IOException
T
- expected return typejsonFile
- json filejsonPath
- the json pathfilters
- filters to be applied to the filter place holders [?] in the pathjava.io.IOException
public static <T> T read(java.io.InputStream jsonInputStream, java.lang.String jsonPath, Predicate... filters) throws java.io.IOException
T
- expected return typejsonInputStream
- json input streamjsonPath
- the json pathfilters
- filters to be applied to the filter place holders [?] in the pathjava.io.IOException
public static ParseContext using(Configuration configuration)
ParseContext
that can be used to parse JSON input. The parse context
is as thread safe as the underlying JsonProvider
. Note that not all JsonProvider are
thread safe.configuration
- configuration to use when parsing JSON@Deprecated public static ParseContext using(JsonProvider provider)
ParseContext
that will parse a given JSON input.provider
- jsonProvider to use when parsing JSONpublic static DocumentContext parse(java.lang.Object json)
Configuration
and
returns a DocumentContext
for path evaluationjson
- inputpublic static DocumentContext parse(java.lang.String json)
Configuration
and
returns a DocumentContext
for path evaluationjson
- stringpublic static DocumentContext parse(java.io.InputStream json)
Configuration
and
returns a DocumentContext
for path evaluationjson
- streampublic static DocumentContext parse(java.io.File json) throws java.io.IOException
Configuration
and
returns a DocumentContext
for path evaluationjson
- filejava.io.IOException
@Deprecated public static DocumentContext parse(java.net.URL json) throws java.io.IOException
Configuration
and
returns a DocumentContext
for path evaluationjson
- urljava.io.IOException
public static DocumentContext parse(java.lang.Object json, Configuration configuration)
Configuration
and
returns a DocumentContext
for path evaluationjson
- inputpublic static DocumentContext parse(java.lang.String json, Configuration configuration)
Configuration
and
returns a DocumentContext
for path evaluationjson
- inputpublic static DocumentContext parse(java.io.InputStream json, Configuration configuration)
Configuration
and
returns a DocumentContext
for path evaluationjson
- inputpublic static DocumentContext parse(java.io.File json, Configuration configuration) throws java.io.IOException
Configuration
and
returns a DocumentContext
for path evaluationjson
- inputjava.io.IOException
@Deprecated public static DocumentContext parse(java.net.URL json, Configuration configuration) throws java.io.IOException
Configuration
and
returns a DocumentContext
for path evaluationjson
- inputjava.io.IOException