jsonrestrfc

RFC 7396 - JSON Merge Patch - Updating objects in a list


The RFC 7396 states:

If the patch is anything other than an object, the result will always be to replace the entire target with the entire patch. Also, it is not possible to patch part of a target that is not an object, such as to replace just some of the values in an array.

For example, if I have this document :

{
  "id": 1,
  "brand_name": "BMW",
  "cars": [{
    "id": 2,
    "model": "S1",
    "cost": 10000
  }]
}

It is my understanding I can't partially update the car with the id #2 in order to update the cost for example:

{
  "id": 1,
  "cars": [{
    "id": 2,
    "cost": 20000
  }]
}

(the idea here is to do not modify the model, just the cost. The ids are present just for the reconciliation)

Is that correct ?

If so, why couldn't we apply this algorithm to deal with lists:

Is that realistic ?


Solution

  • The way I read the the paragraph you sent, I would say.. no you are not able to do this. My understanding is that RFC 7396 is intended as a very simple no-fuss patch format.

    If you want something with more features, consider using RFC 6902 instead.