public class JsonPath extends 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 |
|---|---|
static JsonPath |
compile(String jsonPath,
Filter... filters)
Compiles a JsonPath
|
JsonPath |
copy() |
String |
getPath()
Returns the string representation of this JsonPath
|
boolean |
isPathDefinite()
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[1,2]
$.store.book[?(@.category = 'fiction')]
|
static boolean |
isPathDefinite(String path)
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[1,2]
$.store.book[?(@.category = 'fiction')]
|
static ReadContext |
parse(File json)
Parses the given JSON input using the default
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(File json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(InputStream json)
Parses the given JSON input using the default
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(InputStream json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(Object json)
Parses the given JSON input using the default
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(Object json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(String json)
Parses the given JSON input using the default
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(String json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(URL json)
Parses the given JSON input using the default
Configuration and
returns a ReadContext for path evaluation |
static ReadContext |
parse(URL json,
Configuration configuration)
Parses the given JSON input using the provided
Configuration and
returns a ReadContext for path evaluation |
<T> T |
read(File jsonFile)
Applies this JsonPath to the provided json file
|
<T> T |
read(File jsonFile,
Configuration configuration)
Applies this JsonPath to the provided json file
|
static <T> T |
read(File jsonFile,
String jsonPath,
Filter... filters)
Creates a new JsonPath and applies it to the provided Json object
|
<T> T |
read(InputStream jsonInputStream)
Applies this JsonPath to the provided json input stream
|
<T> T |
read(InputStream jsonInputStream,
Configuration configuration)
Applies this JsonPath to the provided json input stream
|
static <T> T |
read(InputStream jsonInputStream,
String jsonPath,
Filter... filters)
Creates a new JsonPath and applies it to the provided Json object
|
<T> T |
read(Object jsonObject)
Applies this JsonPath to the provided json document.
|
<T> T |
read(Object jsonObject,
Configuration configuration)
Applies this JsonPath to the provided json document.
|
static <T> T |
read(Object json,
String jsonPath,
Filter... filters)
Creates a new JsonPath and applies it to the provided Json object
|
<T> T |
read(String json)
Applies this JsonPath to the provided json string
|
<T> T |
read(String json,
Configuration configuration)
Applies this JsonPath to the provided json string
|
static <T> T |
read(String json,
String jsonPath,
Filter... filters)
Creates a new JsonPath and applies it to the provided Json string
|
<T> T |
read(URL jsonURL)
Applies this JsonPath to the provided json URL
|
<T> T |
read(URL jsonURL,
Configuration configuration)
Applies this JsonPath to the provided json URL
|
static <T> T |
read(URL jsonURL,
String jsonPath,
Filter... filters)
Creates a new JsonPath and applies it to the provided Json object
|
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 JsonPath copy()
public String getPath()
public static boolean isPathDefinite(String path)
public boolean isPathDefinite()
public <T> T read(Object jsonObject)
JsonProviderT - expected return typejsonObject - a container Objectpublic <T> T read(Object jsonObject, Configuration configuration)
JsonProviderT - expected return typejsonObject - a container Objectconfiguration - configuration to usepublic <T> T read(String json)
T - expected return typejson - a json stringpublic <T> T read(String json, Configuration configuration)
T - expected return typejson - a json stringconfiguration - configuration to usepublic <T> T read(URL jsonURL) throws IOException
T - expected return typejsonURL - url to read fromIOExceptionpublic <T> T read(URL jsonURL, Configuration configuration) throws IOException
T - expected return typejsonURL - url to read fromconfiguration - configuration to useIOExceptionpublic <T> T read(File jsonFile) throws IOException
T - expected return typejsonFile - file to read fromIOExceptionpublic <T> T read(File jsonFile, Configuration configuration) throws IOException
T - expected return typejsonFile - file to read fromconfiguration - configuration to useIOExceptionpublic <T> T read(InputStream jsonInputStream) throws IOException
T - expected return typejsonInputStream - input stream to read fromIOExceptionpublic <T> T read(InputStream jsonInputStream, Configuration configuration) throws IOException
T - expected return typejsonInputStream - input stream to read fromconfiguration - configuration to useIOExceptionpublic static JsonPath compile(String jsonPath, Filter... filters)
jsonPath - to compilefilters - filters to be applied to the filter place holders [?] in the pathpublic static <T> T read(Object json, String jsonPath, Filter... 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(String json, String jsonPath, Filter... 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(URL jsonURL, String jsonPath, Filter... filters) throws IOException
T - expected return typejsonURL - url pointing to json docjsonPath - the json pathfilters - filters to be applied to the filter place holders [?] in the pathIOExceptionpublic static <T> T read(File jsonFile, String jsonPath, Filter... filters) throws IOException
T - expected return typejsonFile - json filejsonPath - the json pathfilters - filters to be applied to the filter place holders [?] in the pathIOExceptionpublic static <T> T read(InputStream jsonInputStream, String jsonPath, Filter... filters) throws IOException
T - expected return typejsonInputStream - json input streamjsonPath - the json pathfilters - filters to be applied to the filter place holders [?] in the pathIOExceptionpublic 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 - provider to use when parsing JSONpublic static ReadContext parse(Object json)
Configuration and
returns a ReadContext for path evaluationjson - inputpublic static ReadContext parse(String json)
Configuration and
returns a ReadContext for path evaluationjson - stringpublic static ReadContext parse(InputStream json)
Configuration and
returns a ReadContext for path evaluationjson - streampublic static ReadContext parse(File json) throws IOException
Configuration and
returns a ReadContext for path evaluationjson - fileIOExceptionpublic static ReadContext parse(URL json) throws IOException
Configuration and
returns a ReadContext for path evaluationjson - urlIOExceptionpublic static ReadContext parse(Object json, Configuration configuration)
Configuration and
returns a ReadContext for path evaluationjson - inputpublic static ReadContext parse(String json, Configuration configuration)
Configuration and
returns a ReadContext for path evaluationjson - inputpublic static ReadContext parse(InputStream json, Configuration configuration)
Configuration and
returns a ReadContext for path evaluationjson - inputpublic static ReadContext parse(File json, Configuration configuration) throws IOException
Configuration and
returns a ReadContext for path evaluationjson - inputIOExceptionpublic static ReadContext parse(URL json, Configuration configuration) throws IOException
Configuration and
returns a ReadContext for path evaluationjson - inputIOExceptionCopyright © 2011–2013. All rights reserved.