3

Given something like the following JSON:

{
    "pageId": 2,
    "page_title": "My page",
    "order": 1,
    "active": true,
    "layout": null,
    "unitId": 1,
    "mediaContainers": [
    
    ]
  },

What is the proper way to add an item to the mediaContainers array using the JSON Patch notation? I've tried

{
    "op": "add",
    "path": "/mediaContainers/-",
    "value": {
        "type": "video",
        "mediaContainerVideos": []
    }
}

and

{
    "op": "add",
    "path": "/mediaContainers/0",
    "value": {
        "type": "video",
        "mediaContainerVideos": []
    }
}

with no success, which makes sense now since this array is empty. From what I've seen in the spec, all the examples deal with non-empty arrays, so I'm at a bit of a loss here.

Community
  • 1
  • 1
cbierman
  • 400
  • 5
  • 15

1 Answers1

3

The correct way according to a specification (despite there are no examples with empty arrays) is to go with "-": /mediaContainers/-.

with no success

I think this is a bug of the library you are using since the specs here say "The - character can be used instead of an index to insert at the end of an array.". Empty arrays are no exclusion to that.

Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156