Subject: [Json] JSON Patch and null arrays

From: Ron Alleva <[email-masked]>
Date: Thu, 5 Dec 2019 18:22:26 -0500

Hi all,

I’ve been trying to find a good answer around the internet, but I’ve come
up short. To describe the question in a JSON patch test, I’m wondering if
this should be a valid test:

{ "comment": "Add array element to null",
"doc": {"foo": 1},
"patch": [{"op": "add", "path": “/bar/-", "value": 1}],
"expected": {"foo": 1, "bar": [1]} }

What should “expected” be in this case? Some libraries seem to implement
what is above, but I’ve seen other libraries that insist you must create
the array first, and only then you can add to it, so the above would result
in an error.

The most “user friendly” approach I believe would be the above test case.
In this case, the client does not have to retrieve and interpret the object
to determine if it has to create the array first, it can just add elements.

Is there any opinion on what is a valid interpretation on the spec with
regards to this? Is it just “undefined” because we can’t know that bar is
intended to be an array?

Thanks in advanced,

Ron