|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jayway.jsonpath.JsonPath
public class JsonPath
User: kalle stenflo Date: 2/2/11 Time: 1:03 PM
JsonPath is to JSON what XPATH is to XML, a simple way to extract parts of a given document. JsonPath is available in many programming languages such as Javascript, Python and PHP. JsonPath allows you to compile a json path string to use it many times or to compile and apply in one single on demand operation. Given the Json document:
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")
| Method Summary | ||
|---|---|---|
static JsonPath |
compile(String jsonPath)
Compiles a JsonPath from the given string |
|
|
read(Object json)
Applies this json path to the provided object |
|
static
|
read(Object json,
String jsonPath)
Creates a new JsonPath and applies it to the provided Json object |
|
|
read(String json)
Applies this json path to the provided object |
|
static
|
read(String json,
String jsonPath)
Creates a new JsonPath and applies it to the provided Json string |
|
static
|
readOne(Object json,
String jsonPath)
Creates a new JsonPath and applies it to the provided Json object. |
|
static
|
readOne(String json,
String jsonPath)
Creates a new JsonPath and applies it to the provided Json object. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public <T> List<T> read(Object json)
T - json - a json Object
public <T> List<T> read(String json)
throws ParseException
T - json - a json string
ParseExceptionpublic static JsonPath compile(String jsonPath)
jsonPath - to compile
public static <T> List<T> read(String json,
String jsonPath)
throws ParseException
T - json - a json stringjsonPath - the json path
ParseException
public static <T> List<T> read(Object json,
String jsonPath)
T - json - a json objectjsonPath - the json path
public static <T> T readOne(Object json,
String jsonPath)
T - json - a json objectjsonPath - the json path
public static <T> T readOne(String json,
String jsonPath)
throws ParseException
T - json - a json stringjsonPath - the json path
ParseException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||