avian2 / jsonmerge

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

Alphabetic sorting for arrays #49

Closed pmvieira closed 3 years ago

pmvieira commented 3 years ago

Hi,

would you be open to accept a PR to enable users to sort arrays?

I'm thinking in two options: either extending the classes and modifying the merge function, or simply adding an optional parameter to the current classes. Which one would you prefer? Happy to submit an initial approach for review if you think that's a good idea.

avian2 commented 3 years ago

Hi. Which merge strategies would you like to implement this in? I would probably accept this for append and/or arrayMergeById, but it would need to be general enough - arrays can contain complicated structures, so there would need to be some way of specifying the sort key. Probably similar to idRef argument in arrayMergeById.

pmvieira commented 3 years ago

Hi :) actually what I have tinkered with is exactly on those two merge strategies: append and arrayMergeById. It's current a generic aproach that would take the sort key as an optional parameter, I believe that is inline with what you suggested. I'll submit the PR within the next couple of days so you can have a look.

avian2 commented 3 years ago

I'm closing this since discussion has moved to #51.