3 ms·
Wouldn't it make much more sense to pretty-print the JSON and ship a normal textual diff?
by gwbas1c 5y ago
Wouldn't it make much more sense to pretty-print the JSON and ship a normal textual diff?
- jannes 5y agoThe backend doesn’t necessarily have exactly the same state as the fronted (think about multiple clients). Textual diffs would only work if the starting point is guaranteed to be the same.
- LVB 5y agoIs there a standard pretty print spec?
- lichtenberger 5y agoWhy would it make more sense? You'd first have to sort the keys, then pretty print, then diff: https://www.jvt.me/posts/2020/08/24/pretty-print-json-diff/ https://www.jvt.me/posts/2020/08/24/pretty-print-json-diff/ I'm also using a JSON-diff format in my data store[1], which is accumulated during insertions/updates/deletes in-memory and serialized during a commit, admittedly for large JSON instances (a few Gb and much more). [1] https://github.com/sirixdb/sirix https://github.com/sirixdb/sirix
- gwbas1c 5y ago> You'd first have to sort the keys A lot of that comes down to internal application architecture. If you're working in Javascript / Typescript, where objects are inherently dictionaries / hashsets with ordering; yes, this is true. You will need to sort before serialization in order for the diff to be useful. But: If you're working in a strongly-typed language like C# / Java / Rust / C++, and using an object -> JSON -> object serializer; the order of the elements is often quite explicit and never changes.