Closed pmvieira closed 2 years ago
Thanks for the pull request!
My concern is that i[sortBy]
won't work with array elements that are anything other than JSON objects. Can you make the sortBy
work by resolving a JSON pointer fragment? See how idRef
argument is implemented using resolve_fragment
. This way the sorting could work with any type.
You're welcome 😄 I've been mulling about what you said and it makes perfect sense, however it is important that that more broad use case is nailed correctly so that we don't miss something important. Since we are documenting that this option that we are introducing is meant for complex structures, how you would feel about moving forward as we are now, and then iterate over this in order to nail the other use cases spot-on?
The problem I have with going with this simple solution and then later moving to JSON pointers is that it would be a breaking change (for example, the meaning of sortBy="/foo"
would change). JSON pointers are used throughout JSON schema standard for referring to parts of the document and the syntax is already used in idRef
. I really don't see much reason not to go with it here as well.
I'm closing this pull request now. I've addressed the issues I mentioned in my previous comments myself by building on top of your commit. It's merged into the master branch now.
I dropped your commit that changed the jsonmerge version number, which is why GitHub doesn't consider this a merged pull request.
The latest code now supports sortByRef and sortReverse options for the array strategies. Those implement the sorting feature using JSON pointers.
This PR adds an option to sort complex arrays based on a key when the merge strategy is either append or arrayMergeById