Textually diffing JSON

后端 未结 6 1060
挽巷
挽巷 2020-12-13 15:52

As part of my release processes, I have to compare some JSON configuration data used by my application. As a first attempt, I just pretty-printed the JSON and diff\'ed them

6条回答
  •  囚心锁ツ
    2020-12-13 16:11

    Beyond formatting changes, diffing tool should also order JSON object properties in a stable manner (alphabetically, for example), since the order of properties is semantically meaningless. That is, reordering of properties should not change the meaning of contents.

    Other than this, parsing and pretty-printing in a way that puts at most one entry on a single line might allow use of textual diff. If not, any diff algorithm that works on trees (which is used for xml diffing) should work better.

提交回复
热议问题