avian2 / jsonmerge

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

occasionally converts bool to string during version merge #47

Closed Chaffelson closed 4 years ago

Chaffelson commented 4 years ago

jsonmerge==1.7.0, python 3.7.7 jsonmerge is intermittently converting false to "false" during runs with no apparent change in run parameters when using the version strategy for merging arrays of strings. Then it goes back to correctly returning the bool and not the string for a while, then throws a bad one again.

Input like this in the same spot in two different files: { "name": "hdfs_verify_ec_with_topology_enabled", "value": false }

Output like: "value": [ { "value": false }, { "value": "false" } ],

Schema like: "value": { "type": "string", "mergeStrategy": "version", "mergeOptions": { "keepIfUndef": True } }

avian2 commented 4 years ago

Hi.

You provided very little information to go on. Are you sure you don't sometimes have "value": "false" (a string) in your data? Also, your schema seems to say that "value" property should be a string, which means that input data where "false" is a bool doesn't validate.

jsonmerge assumes that your input data is valid. I don't immediately see a reason why jsonmerge would behave randomly like you describe, but technically feeding it data that does not match the schema can produce unexpected results.

I suggest you fix your schema and first pass your input through jsonschema.validate() before passing it on to jsonmerge. This way you can be sure that your inputs are what you think they are.

Chaffelson commented 4 years ago

Thank you for this advice, I think I was being particularly stupid on this day. The inputs were coming from a cloud service with non-deterministic sorting, so I was (occasionally) getting different input data. Your point about the schema being forced to a string from a bool also helped me find another bug in the processing. Thanks for this excellent module.