I have been reading about JSON Patch. However, I cannot find a solution to my problem. I have a JSON which I need to add a list.
For example:
{
"orders": "food"
}
I need to inject this list of items below the orders attribute.
{
"items": [
{
"item": "ORD-X11",
"buyer": "BY-001-001",
"date": "060220"
}
]
}
So the expected result is:
{
"orders": "food"
"items": [
{
"item": "ORD-X11",
"buyer": "BY-001-001",
"date": "060220"
}
]
}
This is my code in JSON Patch:
{"op": "add", "path": "/items",
"value": {}
}
{"op": "add", "path": "/items/0",
"value": {"item": "ORD-X11"}
}
{"op": "add", "path": "/items/0",
"value": {"buyer": "BY-001-001"}
}
{"op": "add", "path": "/items/0",
"value": {"date": "060220"}
}
Error is appearing that the doc path is missing "/items" which I am trying to add.