Payload JSON Add (payload:json-add)

Payload JSON Add (payload:json-add)

“The payload:json-add-tag helps you adding new tag(s) to an existing json file element.”

Usage:

<payload:json-add path=""! newField=""! value=""!/>

! -mandatory

 

Example

Behaviour

Example

Behaviour

1: add a "subtitle" tag to the second book in the store with a “Men at Arms" value.

 

<property name="subTitle" value="Men at Arms"/> <payload:file method="content" name="jsonContentFromFile" path="/assets/bookstore.json"/> <payload:json-read name="jsonPayload" method="read" jsonString="${jsonContentFromFile}"> <payload:json-add path="store.book[1]" newField="subtitle" value="${subTitle}"/> </payload:json-read>
{ "category":"fiction", "author":"Evelyn Waugh", "title":"Sword of Honour", "price":12.99, "subtitle":"Men at Arms" }

2: add a "language" tag to every book in the store with an “english" value.

 

 

 

 

 

 

 

 

 

 

<property name="lang" value="english"/> <payload:file method="content" name="jsonContentFromFile" path="/assets/bookstore.json"/> <payload:json-read name="jsonPayload" method="read" jsonString="${jsonContentFromFile}"> <payload:json-add path="store.book[*]" newField="language" value="${lang}"/> </payload:json-read>

 

{ "store":{ "book":[ { "category":"reference", "author":"Nigel Rees", "title":"Sayings of the Century", "like":false, "price":8.95, "language":"english" }, { "category":"fiction", "author":"Evelyn Waugh", "title":"Sword of Honour", "price":12.99, "language":"english" }, { "category":"fiction", "author":"Herman Melville", "title":"Moby Dick", "isbn":"0-553-21311-3", "like":true, "price":8.99, "language":"english" }, { "category":"fiction", "author":"J. R. R. Tolkien", "title":"The Lord of the Rings", "isbn":"0-395-19395-8", "like":false, "price":22.99, "language":"english" } ], "bicycle":{ "color":"red", "price":19.95 } }, "expensive":10 }

3: add a "available" tag to the third book in the store with an “false" boolean value.

 

 

<payload:file method="content" name="jsonContentFromFile" path="/assets/bookstore.json"/> <payload:json-read name="jsonPayload" method="read" jsonString="${jsonContentFromFile}"> <payload:json-add path="store.book[2]" newField="available" value="${false}"/> </payload:json-read>
{ "category":"fiction", "author":"Herman Melville", "title":"Moby Dick", "isbn":"0-553-21311-3", "like":true, "price":8.99, "available":false }