536

Meme transcription:

Panel 1: Bilbo Baggins ponders, “After all… why should I care about the difference between int and String?

Panel 2: Bilbo Baggins is revealed to be an API developer. He continues, “JSON is always String, anyways…”

you are viewing a single comment's thread
view the rest of the comments
[-] RustyNova@lemmy.world 107 points 2 days ago* (last edited 2 days ago)

To whoever does that, I hope that there is a special place in hell where they force you to do type safe API bindings for a JSON API, and every time you use the wrong type for a value, they cave your skull in.

Sincerely, a frustrated Rust dev

[-] Rednax@lemmy.world 8 points 2 days ago

The worst thing is: you can't even put an int in a json file. Only doubles. For most people that is fine, since a double can function as a 32 bit int. But not when you are using 64 bit identifiers or timestamps.

[-] firelizzard@programming.dev 31 points 2 days ago

That’s an artifact of JavaScript, not JSON. The JSON spec states that numbers are a sequence of digits with up to one decimal point. Implementations are not obligated to decode numbers as floating point. Go will happily decode into a 64-bit int, or into an arbitrary precision number.

[-] Aux@lemmy.world -1 points 1 day ago

What that means is that you cannot rely on numbers in JSON. Just use strings.

[-] JackbyDev@programming.dev 1 points 21 hours ago

Unless you're dealing with some insanely flexible schema, you should be able to know what kind of number (int, double, and so on) a field should contain when deserializing a number field in JSON. Using a string does not provide any benefits here unless there's some big in your deserialzation process.

[-] Aux@lemmy.world 1 points 19 hours ago

What's the point of your schema if the receiving end is JavaScript, for example? You can convert a string to BigNumber, but you'll get wrong data if you're sending a number.

load more comments (2 replies)
load more comments (14 replies)
this post was submitted on 30 Jun 2024
536 points (98.0% liked)

Programmer Humor

18253 readers
720 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS