JSON
Following functions help you handle JSON documents.
All functions accept an input parameter document
of any type
JsonPath🔗
Object jsonPath(Object document, String jsonPath)
Read the given JSON path from the given document.
Parameters :
document
: The document in which the path will be executedjsonPath
: The JSON path to read
Returns : The read result
Examples :
SpEL : ${#jsonPath(#json, '$.key[0]')}
JsonSerialize🔗
String jsonSerialize(Object obj)
Serialize given object as a JSON string.
Parameters :
obj
: The object to serialize
Returns : The result JSON string
Examples :
SpEL : ${#jsonSerialize(#anyObj)}
JsonSet🔗
String jsonSet(Object document, String path, String value)
Set an existing key value into a given JSON document.
Parameters :
document
: The document to updatepath
: The path in the document to updatevalue
: The new value to set
Returns : The result JSON string
Examples :
SpEL : ${#jsonSet(#json, '$.keyToSet', 'new value')}
JsonSetMany🔗
String jsonSetMany(Object document, Map
Set existing keys values into a given JSON document.
Parameters :
document
: The document to updatemap
: A map of paths in the document to update associated with the new values to set
Returns : The result JSON string
Examples :
SpEL : ${#jsonSetMany(#json, {'$.path1': 'new value1', '$.path2': 'new value2'})}
JsonMerge🔗
String jsonMerge(Object documentA, Object documentB)
Merge a given JSON document into another.
Parameters :
documentA
: The document to updatedocumentB
: The document to set
Returns : The result JSON string
Examples :
SpEL : ${#jsonMerge(#jsonBase, #jsonToAdd)}