Skip to content

Canonicalize JSON before comparison #86

@maininformer

Description

@maininformer

This is a suggestion. I spent an inordinate amount of time, with and without the help of AI trying to figure out why my identical JSON objects are returning a diff only when I run it in my application and not when I am testing it.

I tested by saving the JSONs during dev runtime and loading them and diffing.

I finally realized, it is because jsondiff is okay accepting Python objects that are not JSONs and thereby, producing a diff. But when I json.dumps(json.loads(obj)), it works, because now I have a legit JSON.

Since this project is called jsondiff I highly suggest including this conversion when accepting Python dictionaries. Or, at least, providing a parameter to diff to do that conversion and calling it out in documentation. The only hint I could find, in hind-sight, is the keyword "JSON-like" in the repository.

'Explicit is better than implicit'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions