avian2 / jsonmerge

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

Add renameConflicts option to ObjectMerge strategy #26

Closed aadu closed 6 years ago

aadu commented 7 years ago

Passing "renameConflicts": true in mergeOptions will cause conflicting properties to be renamed instead of overwritten when using the ObjectMerge strategy. By default, the new property name of the conflicting file will be the previous property name with '-conflict' appended to it. The suffix and/or prefix used for renaming the conflicting property can be set using the renameSuffix and renamePrefix properties in mergeOptions. Anyways, neat library (discovered it a little earlier today). The only thing I was missing was the ability to rename conflicting fields.

avian2 commented 7 years ago

Hi. Thanks for your pull request. Can you please add some more details about the new options to the README, similarly to how other options are documented? At the moment, I don't exactly understand how this works.

For example, I don't understand what is supposed to happen with nested changes. For example, this code gives me a RefResolutionError: Unresolvable JSON pointer: u'a/a':

        schema = {
            'mergeStrategy': 'objectMerge',
            'mergeOptions': {'renameConflicts': True}}

        base = None
        base = jsonmerge.merge(base, {'a': {'a':1}}, schema)
        base = jsonmerge.merge(base, {'a': {'b':2}}, schema)

What happens on subsequent merges? It seems that the renamed property simply gets overwritten.