public class SimpleJsonValueModifier
extends java.lang.Object
String jsonSource = "{\"testArray\":[1,2,3,{\"A\":5,\"B\":7},\"X\"],\"tail\":9}";
SimpleJsonValueModifier jsonValueModifier = new SimpleJsonValueModifier(jsonSource);
if (jsonValueModifier.update("testArray.[3].A", Json.value(23))) {
System.out.println(jsonValueModifier.getResultRoot().toString() + " | " + jsonValueModifier.getOldValue().toString());
// {"testArray":[1,2,3,{"A":23,"B":7},"X"],"tail":9} | 5
}
else {
System.out.println("[No match found]");
}
| Constructor and Description |
|---|
SimpleJsonValueModifier(java.io.Reader jsonReader)
Create a new instance from a Json Reader.
|
SimpleJsonValueModifier(java.lang.String jsonSource)
Create a new instance from a Json String.
|
| Modifier and Type | Method and Description |
|---|---|
JsonValue |
getOldValue()
Get the old value of the latest executed update.
|
JsonValue |
getResultRoot()
Get the root of the modified Json data.
|
boolean |
update(java.lang.String simpleQuery,
JsonValue newValue)
Modify/update a Json value selected by a simple Json query.
|
public SimpleJsonValueModifier(java.lang.String jsonSource)
jsonSource - a String containing the Json datapublic SimpleJsonValueModifier(java.io.Reader jsonReader)
throws java.io.IOException
jsonReader - a Reader for the Json datajava.io.IOException - if somewhat fails.public boolean update(java.lang.String simpleQuery,
JsonValue newValue)
simpleQuery - the simple query to address the value. Examples: "[0].datapoints.[2].[1]", "customers.person.name"newValue - the new valuejava.lang.IllegalArgumentException - if the root of the Json data is not an Object or Arraypublic JsonValue getResultRoot()
public JsonValue getOldValue()
update(String, JsonValue)