avian2 / jsonmerge

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

How to merge ordered jsons (OrderedDicts)? #25

Closed wjur closed 7 years ago

wjur commented 7 years ago

If I merge two ordered dict then the result is a dict. I know that order in json is not important, but we want the fields in our json file to be in a particular (for readability). Are OrderedDicts supported? Maybe I'm missing something. Is there any workaround for this?

avian2 commented 7 years ago

There is currently no support for OrderedDicts in jsonmerge.

After a quick look through the code, your OrderedDicts in the input are probably converted to unordered by the dict() call in ObjectMerge.merge() method. I guess you could change that to copy.copy() to preserve the original class.

Another option would be to implement something like the object_pairs_hook in Python's json.load().

avian2 commented 7 years ago

FYI pull request #27 implements support for OrderedDicts. You might want to check if it fits your particular use case.