josephburnett / jd

JSON diff and patch
MIT License
826 stars 38 forks source link

Diff only structure, ignore (leaf?) values #58

Open wasker opened 1 year ago

wasker commented 1 year ago

My use case is to compare JSON files with localized data. These files have specific structure and I need to ensure that all locales follow the same structure.

E.g., these are the same:

{
    "qwe": {
        "asd": {
            "label": "something",
            "url": "http://blah.com"
        }
    }
}

{
    "qwe": {
        "asd": {
            "label": "lorem ipsum",
            "url": "http://blah.lorem"
        }
    }
}

These are not the same:

{
    "qwe": {
        "asd": {
            "label": "something",
            "target": "_blank",
            "url": "http://blah.com"
        }
    }
}

{
    "qwe": {
        "asd": {
            "label": "lorem ipsum",
            "url": "http://blah.lorem"
        },
        "zxc": {
            "button": "yadda"
        }
    }
}

Would that be possible/feasible to accommodate with this tool?

josephburnett commented 1 year ago

There are a few similar requests. One for defining equality with a regular expression and one to ignore floating point rounding errors. So it would be worth considering how we can address in general the problem of defining equality constraints.

Yes, this cool could be modified to ignore the actual leaf values. But I wonder if a schema validator would be a better fit. Is the structure known ahead of time? If you can define the shape ahead of time with JSON Schema then determining if the files have the right structure is just schema validation.

wasker commented 1 year ago

Thanks for suggestions. Unfortunately, there's no schema for these files and there're lots of these files to even attempt produce schema by hand. I was hoping that short-circuiting the diffing logic I could get this done.