ReplaceItemsArrayByPathJSON
Replaces an element within an array based on a JSON path.
ReplaceItemsArrayByPathJSON(
array: str,
filterPath: str,
item: str
)
Where:
- array: An array in the format '[{"first_name": "Brad", "last_name": "Pitt"}]' for example.
- filterPath: A string in JSONPath format to traverse the path to an element in a JSON structure.
- item: A string to replace within the array at the specified JSONPath.
Example
The example below replaces an element in an array by specifying its JSONPath.
{{set(
name="MyArray",
value=AppendItemsArrayJSON(
array="[]",
items=[
'{
"first_name": "Brad",
"last_name": "Pitt"
}',
'{
"first_name": "Matt",
"last_name": "Damon"
}'
]
)
)}}
{{SendMessage(message=MyArray)}}
{{set(
name="PathArray",
value=ReplaceItemsArrayByPathJSON(
array=MyArray,
filterPath="[1].first_name",
item='
{
"first_name": "Angelina",
"last_name": "Jolie"
}
'
)
)}}
{{SendMessage(message=PathArray)}}
[{"first_name":"Brad","last_name":"Pitt"},{"first_name":"Matt","last_name":"Damon"}]
[{"first_name":"Brad","last_name":"Pitt"},{"first_name":"Angelina","last_name":"Jolie"}]
Updated 8 months ago