You can modify JSON objects and JSON arrays.
{
"name" : "John Doe",
"age" : -1,
"known" : false,
"address" : { "street" : null,
"city" : "unknown" },
"belongings" : ["this", "that", "the other"]
}
(Message):JSON = ( ['json' : 0xhhhhhh]
(0x01000000:Object):Data = (
(0x03000000:NameValue): name = 'John Doe' (CHARACTER)
(0x03000000:NameValue): age = -1 (INTEGER)
(0x03000000:NameValue): known = FALSE (BOOLEAN)
(0x01000000:Object ): address = (
(0x03000000:NameValue): street = NULL (UNKNOWN)
(0x03000000:NameValue): city = 'unknown' (CHARACTER)
)
(0x01001000:Array ): belongings = (
(0x03000000:NameValue): Item = 'this' (CHARACTER)
(0x03000000:NameValue): Item = 'that' (CHARACTER)
(0x03000000:NameValue): Item = 'the other' (CHARACTER)
)
)
)
SET OutputRoot.JSON.Data.age = InputRoot.JSON.Data.age + 22; -- Set age to 21
SET OutputRoot.JSON.Data.belongings.Item[4] = 'an other';
SET OutputRoot.JSON.Data.belongings.Item[5] = 'and another';
$output_assembly->JSON->Data->address->age = $input_assembly->JSON->Data->address->age + 22; // Set age to 21
$output_assembly->JSON->Data->belongings[2] = 'an other';
$output_assembly->JSON->Data->belongings[3] = 'and another';
For
more information about PHP arrays, including multidimensional arrays,
see Using PHP arrays with JSON.MbElement ageEl = message.getRootElement().getLastChild().getFirstElementByPath("/JSON/Data/age");
int age = ((Integer)ageEl.getValue()).intValue();
ageEl.setValue(age + 22); // Set age to 21
inMessage.getRootElement().getLastChild().getFirstElementByPath("/JSON/Data/belongings/Item[3]").setValue(an other');
JSON with a multidimensional array
{
"customer" : "Joe",
"orders" : [ [ "thing1", 1, 10.1 ],
[ "thing2", 2, 20.2 ] ]
}
(Message):JSON = ( ['json' : 0xhhhhhh]
(0x01000000:Object):Data = (
(0x03000000:NameValue):customer = 'Joe' (CHARACTER)
(0x01001000:Array):orders = (
(0x01001000:Array):Item = (
(0x03000000:NameValue):Item = 'thing1' (CHARACTER)
(0x03000000:NameValue):Item = 1 (INTEGER)
(0x03000000:NameValue):Item = 1.01E+1 (FLOAT)
)
(0x01001000:Array):Item = (
(0x03000000:NameValue):Item = 'thing2' (CHARACTER)
(0x03000000:NameValue):Item = 2 (INTEGER)
(0x03000000:NameValue):Item = 2.02E+1 (FLOAT)
)
)
)
)
InputRoot.JSON.Data.orders.Item[1].Item[1] -- 'thing1'
InputRoot.JSON.Data.orders.*[2].*[3] –- 2.02E+1
$output_assembly->JSON->Data.orders[0][0] // “thing1”
$output_assembly->JSON->Data.orders[1][2] // 2.02E+1
inMessage.getRootElement().getFirstElementByPath("/JSON/Data/orders/Item[1]/Item[1]"); // 'thing1'
inMessage.getRootElement().getFirstElementByPath("/JSON/Data/orders/*[2]/*[3]"); // '2.02'