public class JsonContext extends Object implements DocumentContext
| Modifier and Type | Method and Description |
|---|---|
DocumentContext |
add(JsonPath path,
Object value)
Add value to array at the given path
|
DocumentContext |
add(String path,
Object value,
Predicate... filters)
Add value to array
|
Configuration |
configuration()
Returns the configuration used for reading
|
DocumentContext |
delete(JsonPath path)
Deletes the given path
|
DocumentContext |
delete(String path,
Predicate... filters)
Deletes the given path
|
Object |
json()
Returns the JSON model that this context is operating on
|
String |
jsonString()
Returns the JSON model that this context is operating on as a JSON string
|
ReadContext |
limit(int maxResults)
Stops evaluation when maxResults limit has been reached
|
DocumentContext |
map(JsonPath path,
MapFunction mapFunction)
Replaces the value on the given path with the result of the
MapFunction. |
DocumentContext |
map(String path,
MapFunction mapFunction,
Predicate... filters)
Replaces the value on the given path with the result of the
MapFunction. |
DocumentContext |
put(JsonPath path,
String key,
Object value)
Add or update the key with a the given value at the given path
|
DocumentContext |
put(String path,
String key,
Object value,
Predicate... filters)
Add or update the key with a the given value at the given path
|
<T> T |
read(JsonPath path)
Reads the given path from this context
|
<T> T |
read(JsonPath path,
Class<T> type)
Reads the given path from this context
|
<T> T |
read(JsonPath path,
TypeRef<T> type)
Reads the given path from this context
Sample code to create a TypeRef
TypeRef ref = new TypeRef |
<T> T |
read(String path,
Class<T> type,
Predicate... filters)
Reads the given path from this context
|
<T> T |
read(String path,
Predicate... filters)
Reads the given path from this context
|
<T> T |
read(String path,
TypeRef<T> type)
Reads the given path from this context
Sample code to create a TypeRef
TypeRef ref = new TypeRef |
DocumentContext |
renameKey(JsonPath path,
String oldKeyName,
String newKeyName)
Renames the last key element of a given path.
|
DocumentContext |
renameKey(String path,
String oldKeyName,
String newKeyName,
Predicate... filters)
Renames the last key element of a given path.
|
DocumentContext |
set(JsonPath path,
Object newValue)
Set the value a the given path
|
DocumentContext |
set(String path,
Object newValue,
Predicate... filters)
Set the value a the given path
|
ReadContext |
withListeners(EvaluationListener... listener)
Adds listener to the evaluation of this path
|
public Configuration configuration()
ReadContextconfiguration in interface ReadContextconfiguration in interface WriteContextpublic Object json()
ReadContextjson in interface ReadContextjson in interface WriteContextpublic String jsonString()
ReadContextjsonString in interface ReadContextjsonString in interface WriteContextpublic <T> T read(String path, Predicate... filters)
ReadContextread in interface ReadContextpath - path to readfilters - filterspublic <T> T read(String path, Class<T> type, Predicate... filters)
ReadContextread in interface ReadContextpath - path to readtype - expected return type (will try to map)filters - filterspublic <T> T read(JsonPath path)
ReadContextread in interface ReadContextpath - path to applypublic <T> T read(JsonPath path, Class<T> type)
ReadContextread in interface ReadContextpath - path to applytype - expected return type (will try to map)public <T> T read(JsonPath path, TypeRef<T> type)
ReadContext
TypeRef ref = new TypeRef>() {};
read in interface ReadContextpath - path to applytype - expected return type (will try to map)public <T> T read(String path, TypeRef<T> type)
ReadContext
TypeRef ref = new TypeRef>() {};
read in interface ReadContextpath - path to applytype - expected return type (will try to map)public ReadContext limit(int maxResults)
ReadContextlimit in interface ReadContextpublic ReadContext withListeners(EvaluationListener... listener)
ReadContextwithListeners in interface ReadContextlistener - listeners to addpublic DocumentContext set(String path, Object newValue, Predicate... filters)
WriteContextset in interface WriteContextpath - path to setnewValue - new valuefilters - filterspublic DocumentContext set(JsonPath path, Object newValue)
WriteContextset in interface WriteContextpath - path to setnewValue - new valuepublic DocumentContext map(String path, MapFunction mapFunction, Predicate... filters)
WriteContextMapFunction.map in interface WriteContextpath - path to be converted setmapFunction - Converter object to be invokedfilters - filterspublic DocumentContext map(JsonPath path, MapFunction mapFunction)
WriteContextMapFunction.map in interface WriteContextpath - path to be converted setmapFunction - Converter object to be invoked (or lambda:))public DocumentContext delete(String path, Predicate... filters)
WriteContextdelete in interface WriteContextpath - path to deletefilters - filterspublic DocumentContext delete(JsonPath path)
WriteContextdelete in interface WriteContextpath - path to deletepublic DocumentContext add(String path, Object value, Predicate... filters)
WriteContext
List array = new ArrayList(){{
add(0);
add(1);
}};
JsonPath.parse(array).add("$", 2);
assertThat(array).containsExactly(0,1,2);
add in interface WriteContextpath - path to arrayvalue - value to addfilters - filterspublic DocumentContext add(JsonPath path, Object value)
WriteContextadd in interface WriteContextpath - path to arrayvalue - value to addpublic DocumentContext put(String path, String key, Object value, Predicate... filters)
WriteContextput in interface WriteContextpath - path to objectkey - key to addvalue - value of keyfilters - filterspublic DocumentContext renameKey(String path, String oldKeyName, String newKeyName, Predicate... filters)
WriteContextrenameKey in interface WriteContextpath - The path to the old key. Should be resolved to a map
or an array including map items.oldKeyName - The old key name.newKeyName - The new key name.filters - filters.public DocumentContext renameKey(JsonPath path, String oldKeyName, String newKeyName)
WriteContextrenameKey in interface WriteContextpath - The path to the old key. Should be resolved to a map
or an array including map items.oldKeyName - The old key name.newKeyName - The new key name.public DocumentContext put(JsonPath path, String key, Object value)
WriteContextput in interface WriteContextpath - path to arraykey - key to addvalue - value of keyCopyright © 2025. All rights reserved.