fbpx
Skip to main content

MIDI Forum

MIDI-CI Property Ex...
 
Notifications
Clear all

MIDI-CI Property Exchange: adding new element to a JSON array in partial updates

3 Posts
2 Users
1 Reactions
270 Views
Atsushi
Posts: 11
Active Member
Topic starter
 

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?

 
Posted : 14/03/2024 8:00 pm
Posts: 1
New Member
 

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:

  1. Use set-full: The PE specification allows for the use of set-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 use set-full to replace the entire data structure with the updated one.
  2. Combine set-partial operations: If the parent object or array exists, you could use a combination of set-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.
  3. 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.

 
Posted : 15/03/2024 4:02 am
Andrew Mee reacted
Atsushi
Posts: 11
Active Member
Topic starter
 

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

 
Posted : 19/03/2024 2:42 am
Share: