I have been investigating MIDI-CI Property Exchange features and noticed that it is unclear if/how I can add a new array element to a JSON node using RFC 6901 JSON Pointer. There is similar question to (general) JSON processing in a StackOverflow Q: https://stackoverflow.com/questions/47670366/jsonpatch-adding-element-to-array-and-creating-it-if-not-exist
If I understand correctly, RFC 6902 (JSON Patch) can handle it, but PE `set-partial` expects PE implementations to only support RFC 6901. It would result in "no such JSON node" kind of error if I try to access to non-existent path. Is there any solution for this kind of operation?
According to the MIDI-CI Property Exchange (PE) specification, the set-partial
operation is indeed limited to using JSON Pointers as defined in RFC 6901. This means that there is no direct way to add a new element to an array using set-partial
if the target array path does not exist.
However, there are a few potential workarounds or alternative approaches you could consider:
- Use
set-full
: The PE specification allows for the use ofset-full
to replace the entire data structure with a new one. If you have the ability to construct the desired data structure (including the new array element) beforehand, you can useset-full
to replace the entire data structure with the updated one. - Combine
set-partial
operations: If the parent object or array exists, you could use a combination ofset-partial
operations to first create an empty array (if it doesn't exist) and then append the new element to that array in a subsequent operation. - Use a different protocol: If your use case requires more advanced JSON manipulation capabilities, you might need to consider using a different protocol or API that supports JSON Patch (RFC 6902) or other JSON manipulation operations. However, this would deviate from the MIDI-CI PE specification.
It's worth noting that the MIDI-CI PE specification is designed to be a lightweight protocol for exchanging property data, and it intentionally limits the operations to a subset of JSON Pointer functionality for simplicity and interoperability reasons.
If your use case requires more advanced JSON manipulation capabilities, and you have the flexibility to extend or deviate from the MIDI-CI PE specification, you could consider implementing support for JSON Patch (RFC 6902) or exploring other libraries or APIs that provide the desired functionality.
Alternatively, if you need to strictly adhere to the MIDI-CI PE specification, you might need to find alternative ways to structure your data or perform the necessary operations outside of the PE protocol, depending on your specific requirements and constraints.
Hi,
Could you please elaborate on this -
> for simplicity and interoperability reasons.
I do not see any particular need for interoperability. What is the interoperability with? To my understanding, MIDI-CI Property Exchange is a totally new specification that (unlike MIDI 1.0 channel voice messages) does not have any corresponding legacy specification, but is there?
Thanks