isaacs / github

Just a place to track issues and feature requests that I have for github
2.2k stars 129 forks source link

JSON Diffs #67

Open nathanathan opened 11 years ago

nathanathan commented 11 years ago

One Github features I like a lot is the way it can show image diffs. I think this sort of content specific diffing could be useful in other places. One type of content I think it would be especially beneficial for is JSON data. Line-by-line diffs are usually good enough, but in cases where there are no linebreaks, or your keys get scrambled for whatever reason, structural diffs can be quite nice. There are some libraries out there that can do the diffing.

yocontra commented 10 years ago

Setting git's diff algorithm to "patience" might help solve the key scramble problem. +1 to this

rlidwka commented 10 years ago

JSON (especially json with no line breaks) is not a source code, it's a machine-generated code. So, it has no place in git repository anyway.

knalli commented 10 years ago

Ehm.. what?! Only machine-generated code? No way. JSON is often used for configuration purpose.

Please do yourself a favor and search for that common files like component.json, package.json or even in web-centric fields bower.json. :)

rlidwka commented 10 years ago

Ehm.. what?! Only machine-generated code?

Yes. Humans need comments, unquoted keys and many other things json fails to provide.

Please do yourself a favor and search for that common files like component.json, package.json or even in web-centric fields bower.json. :)

It is a misuse of json.

If you're doing that, please stop right now, because it'll cause big inconveniences when your package will grow. For example, it doesn't support comments. And it doesn't have trailing commas which is bad for source control.

As an alternative, please consider using either JSON5 or YAML.

knalli commented 10 years ago

Okay. Your points are valid, at least the facts.

Anyway: Please consider widely used patterns which would be useful for stuff which is already available (the past), which is now available (the present) and which will be available (the future). Until better solutions are widely accepted & used[!], we all would have a benefit. (Update: YAML is not new, don't get me wrong.)

As an alternative, please consider using either JSON5 or YAML. It is nice if you have the choice. But sometimes you can't.

nathanathan commented 10 years ago

it's a machine-generated code. So, it has no place in git repository anyway.

Why not? Github's revision tracking and collaboration capabilities are useful for lots of types of data.

rlidwka commented 10 years ago

Why not?

I've seen too much issues when you have a source (i.e. coffeescript) and compiled files (i.e. javascript compiled from coffee) in git. You need to constantly worry about keeping both of them in sync, and dealing with people who send a pull request to update one, but not the other.