3 ms·
JSON Diff Released
- jrockway 18y agoInteresting. Unfortuantely JSON can't distinguish between lists and sets. So you can't get a good diff of arrays. Does: ['foo','bar','baz'] -> ['baz','bar','foo'] Diff to: @@ -1,3 +1,3 @@ -baz +foo bar -foo +baz Or are they the same?
- tlrobinson 18y agoJavaScript (and thus JSON) arrays are lists, not sets. You can implement sets using arrays, but this diffs JSON, not your implementation of sets. It diffs arrays "correctly", though not intelligently. If you have [1,2,3,4,5] and [1,3,4,5] it won't tell you the item at index 1 was removed, it will tell you the items at index 1, 2, 3 were changed and index 4 was removed. Thus it does need a little work, but not in the context you described. p.s. I'm the author of the JSON Diff tool.
- ajross 18y agoYou can implement a set as an object, though. One presumes (not having tried the tool) that it's not sensitive to order differences in object field initializers. Basically, "set" isn't a native data structure in Javascript, so it doesn't exist in JSON either. You can use arrays for that purpose, but just as with code, you need to be a little careful. Probably you should consider storing all your "sets" in a normalized (e.g. sorted) form.
- boucher 18y agoIt's easy enough to check, and they do in fact diff to the above.
- jrockway 18y agoSure, but that's decided by the diff tool, not by the data.
- gojomo 18y agoWhy don't you try it, rather than post a comment with misleading statements like "you can't get a good diff of arrays"?