|
|
|
|
|
by chimeracoder
4584 days ago
|
|
JSON is always going to be a bit more difficult to parse in statically typed languages than dynamically typed ones. The amusing part is that most APIs use JSON as if it were statically typed - except for null/undefined, very few APIs return values of more than one possible type for a given key[0]. It doesn't always have to be so bad, though, even in statically typed languages. For example, I created a tool in Go to automatically generate struct definitions, given an example JSON response: https://github.com/ChimeraCoder/gojson In the time that I've been using it (since last December), I don't think I've run into any issues with an API returning an incorrect type for a particular key[1]. [0] For the record, I'm not complaining. The alternative would be a nightmare to deal with.
[1] Though they do sometimes return a different object altogether; this is an issue regardless of which type system you use. |
|
> except for null/undefined,
That's not a small issue.
Not only do JSON responses for API's vary a great deal from request to request, some handle errors without HTTP response code's. So the JSON you get back can be very different then you might expect otherwise.