2 ms·
It actually is a JSON problem, specifically because ... > You gotta remember that JSON doesn’t support all of the types that many languages do. So you need to
by eyelidlessness 6y ago
It actually is a JSON problem, specifically because ...
> You gotta remember that JSON doesn’t support all of the types that many languages do. So you need to engineer around that
And now you have N+1 problems.
> You can’t get mad at JSON for not being good at this.
It's not about being mad at JSON or even critical. It's about recognizing that the format's simplicity pushes some logic into either your language, your codec/serdes or your application itself.
Unfortunately, what I've seen is that people opt for the "application itself" approach, do it completely ad hoc, and trust all kinds of godawful things that have no reason to be trusted.
If you're using JSON and represent richer types (edit to add: and almost every JSON API does, there's no Date type so you're definitely making some assumptions about names or string [or bless your heart number] data), you should either:
- Use a transport format that extends it in a consistent way like Transit.
- Use the same codec logic on coupled client/server, and make your server's codec logic a first class part of your SDK which you should provide.
There's good tools for sharing and translating type definitions. Use those too. There are better tools even than that (one of which I'm working on, and hope to have a `Show HN` soon).
- Spivak 6y agoI think a shorter way of saying this is that everyone ad-hoc invents new formats that are subsets of JSON but don’t implement validators or parsers for them.
- eyelidlessness 6y agoThat’s true (except I assume you mean superset) but I think some of the shortening of it has a risk of masking just how awful that is. And in this case it’s not a JSON problem, it’s general data interchange design. I’ve worked on too many applications that have HTTP body, query, header, cookie logic deep in business logic. Or distributed systems just pulling rando values out of messages. Or database queries making assumptions about blob data. It’s pervasive. Engineers routinely design systems where they overload the types of their tools and just whistle while their world burns.