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) |
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)
Parses the given JSON input using the default
Configuration and
returns a DocumentContext for path evaluation |
static DocumentContext |
parse(java.net.URL json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a DocumentContext for path evaluation |
<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)
Creates a new JsonPath and applies it to the provided Json object
|
<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 a given JSON input. |
static ParseContext |
using(JsonProvider provider)
Creates a
ParseContext that will parse a given JSON input. |
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)
JsonProviderT - expected return typejsonObject - a container Objectpublic <T> T read(java.lang.Object jsonObject,
Configuration configuration)
JsonProviderT - 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 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 objectvalue - the key to add or updatevalue - the new valueconfiguration - configuration to usepublic <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.IOExceptionpublic <T> T read(java.io.File jsonFile)
throws java.io.IOException
T - expected return typejsonFile - file to read fromjava.io.IOExceptionpublic <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.IOExceptionpublic <T> T read(java.io.InputStream jsonInputStream)
throws java.io.IOException
T - expected return typejsonInputStream - input stream to read fromjava.io.IOExceptionpublic <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.IOExceptionpublic <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.IOExceptionpublic 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 pathpublic 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.IOExceptionpublic 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.IOExceptionpublic 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.IOExceptionpublic static ParseContext using(Configuration configuration)
ParseContext that can be used to parse a given JSON input.configuration - configuration to use when parsing JSONpublic 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.IOExceptionpublic static DocumentContext parse(java.net.URL json) throws java.io.IOException
Configuration and
returns a DocumentContext for path evaluationjson - urljava.io.IOExceptionpublic 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.IOExceptionpublic static DocumentContext parse(java.net.URL json, Configuration configuration) throws java.io.IOException
Configuration and
returns a DocumentContext for path evaluationjson - inputjava.io.IOException