3 ms·
Pros: - it's a lot like XML but with less red tape. Looks nicer to humans. Also allows expressing the semantic difference between an (ordered) array and a map.
by mvindahl 10y ago
Pros:
- it's a lot like XML but with less red tape. Looks nicer to humans. Also allows expressing the semantic difference between an (ordered) array and a map.
- it maps extremely well to Javascript, and a lot of APIs are consumed by web clients written in Javascript these days
I think the latter is the real explanation.
That being said, I agree that JSON is not a panacea. My personal pain points:
1) Missing an elegant way to express an unordered set. IMHO the three basic collection data types are array, set, and map. I think JSON would be stronger if it could express a set like you can do in ES these days: { "a", "b " }
2) Not really DRY if you encode a large array of objects and sned them over the wire. So yeah, your API should support more compact formats as well.
3) Allowing comments would be really nice when we use JSON for e.g. package.json. I don't think it would make the parsers any slower so why not? XML has it.