avian2 / jsonmerge

Merge a series of JSON documents.
MIT License
214 stars 25 forks source link

multiple idRef and ignoreId #44

Closed mrehder closed 4 years ago

mrehder commented 4 years ago

support for multiple "keys" in an array seems to be missing. This is required for some use-cases where more than one property is used as the "key" of the array.

avian2 commented 4 years ago

Hi. Supporting multiple key references in arrayMergeById sounds like a useful feature. Unfortunately your short description really doesn't say much about how you think this idea should work. While it might look simple at the first glance, I covering all the corner cases of this feature seems complicated.

For example, how exactly would multiple idRefs behave? Is each object pointed to by idRef unique (making each object in the array possibly occupying more than one slot in the unique set)? Or is the set of all present idRef'd objects in unique? How to handle array elements that have one or more idRef'd object missing. How is ignoreId handled in the case of multiple idRefs per element?

mrehder commented 4 years ago

it's the set of items forming a unique identification. A compound key. For example, an array of city theaters keyed by City and Theater names - both city and theater values are needed to identify a unique array entry. One could have defined a single key but then it wouldn't be easy to do searches/sorts by city etc. I think any entry missing the necessary keys is declared an exception, since without all keys there can't be proper matching.

I don't have a usecase for multiple ignoreIDs.

mrehder commented 4 years ago

"idRefs" (plural) could be added to maintain BWC. It would have an array of ids as its value. The code then looks for a match to "idRef" or "within" the set for "idRefs"