I have a json object like this:
{
"content" : [
{
"id" : 54
"foo" : "bar"
},
{
"id" : 43
"foo" : "bar"
},
{
"id" : 76
"foo" : "bar"
}
]
}
If I want to add multiple items to the content array (order doesn't matter) can I add to it with a json patch with a single line/ operation with something like this?
{ "op": "add", "path": "/content/-", "value": [
{
"id" : 34
"foo" : "bar"
},
{
"id" : 23
"foo" : "bar"
},
{
"id" : 87
"foo" : "bar"
}
]
}
Or do I have to do an additional line for each object I want to add?
EDIT: To be clear I want to append, not replace the content.
This processor extracts multiple values from a field containing a JSON array and concatenates them into a multivalued field.
How it works. A JSON Patch document is just a JSON file containing an array of patch operations. The patch operations supported by JSON Patch are “add”, “remove”, “replace”, “move”, “copy” and “test”. The operations are applied in order: if any of them fail then the whole patch operation should abort.
JSON Patch is a web standard format for describing changes in a JSON document. It is meant to be used together with HTTP Patch which allows for the modification of existing HTTP resources. The JSON Patch media type is application/json-patch+json .
JSON Patch is a format for specifying updates to be applied to a resource. A JSON Patch document has an array of operations. Each operation identifies a particular type of change. Examples of such changes include adding an array element or replacing a property value.
Unfortunately, this seems not (yet?) possible... as the Json Patch specification states :
https://www.rfc-editor.org/rfc/rfc6902#section-4.1
The "add" operation performs one of the following functions, depending upon what the target location references:
If the target location specifies an array index, a new value is inserted into the array at the specified index.
If the target location specifies an object member that does not already exist, a new member is added to the object.
If the target location specifies an object member that does exist, that member's value is replaced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With