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…”

7 points

I feel this in my bones. As an OG dev, I had this incredible urge to smack people when I was working for my last job and I saw the API specs with everything being sent as strings through JSON. Boolean? Sure, let’s use a string. Integers? Sure we’ll do conversion in our code, that’ll be more efficient… So fucking infuriating. Oh and don’t get me started on JsonSchema T_T

permalink
report
reply
3 points

Please do get started. I am curious.

permalink
report
parent
reply
3 points
*

JsonSchema is a way to validate some JSON. A great thing when you want to stop any sort of malformed data from coming in. Instead of wrecking your head in your code testing whether this bit here is not null, or is that string a valid boolean (I still remember that shitty piece of code they had, ugh!) or that bit is empty or that one is an actual number, or a string that can only have such and such value, well, you can formalise all this in one place, as a data file instead of code. Very convenient.

Except when it turns out you’re using a JSON library that’s not one, not two, but six major versions behind, and the security department won’t greenlight you using anything recent because… fuck you, that’s why. And to add insult to injury, we were the Quality department. Responsible for analysing the code quality of thousands of coders, around a hundred thousand programs (mostly COBOL but also C#), of a European banking group… The JSON schema was for adding a layer of non existant security to our API. But no, let’s keep accepting shitty malformed JSON (because of course we kept receiving shitty JSON; that’s why we wanted to implement this)

So I had to rewrite a lot of custom code to patch the bugs we found in the library, and none of the nifty tools that let you put in json and generate json schema would work for us. Heck, they even have JsonSchema to validate your JsonSchema but those wouldn’t work either, so far behind our version was.

Fucking awesome experience. I’m glad it’s behind me.

permalink
report
parent
reply
20 points

Once we had a “sr developer” join a project from a consulting group. The project wasn’t going well so me and another dev started helping with some tasks as well.

After a couple days of helping, trying to get his web application to work with data from an API he turns to us and says “oh, json is just a string.”

The other developer from our team stared at him for a few seconds, stood up, walked out of the room and told the project manager something along the lines of “if that guy ever comes back in the building I’ll quit”

So yeah, json is just a string… But if that’s the end of your knowledge you’re in for a bad day.

permalink
report
reply
5 points

“if that guy ever comes back in the building I’ll quit”

You can’t just leave a story like that lol, did “sr dev” come back into the building? Did the other dev follow through on his threat? So many questions

permalink
report
parent
reply
5 points

Ha yeah “Sr dev” was never seen again, the team member stuck around for quite a few more years.

permalink
report
parent
reply
6 points
*

The meme format is awesome, but JSON differentiates strings with ".

{ "key": 1337 } vs { "key": "1337" }.

You might be thinking yaml? (Though it supports ' and " for explicit string types, technically)

But integer vs float? Good luck.

permalink
report
reply
11 points

The joke is that, regardless of how the type is declared in json, you are parsing a string. (your json blob is just a series of characters, not raw binary data)

permalink
report
parent
reply
2 points

Yes. And many people here doesn’t seem to get that.

I’m not a dev of any kind. I occasionally write some bash and awk scriots to automate some things and if I need some kind of plain text (non-binary) data format I prefer tsv over json.

So why do I still get this? Is it just that many json advocates want to make sure others know json does support other data types than plain string?

permalink
report
parent
reply
17 points

I love when an API takes a json payload, and one of the json fields is a string that contains json, so I have to serialize/deserialze in stages 😭

permalink
report
reply
0 points

Holy shit, I’m sorry.

Though I once proposed an API like that for user preferences. I just needed “someone” (that wasn’t the client) to store a bunch of data for me. The backend doesn’t interpret it, the backend doesn’t edit it, so why should they deserialize and serialize it again? Just give it to me when I ask for it, kay?

permalink
report
parent
reply
0 points

Looks like you have a shitty arch

permalink
report
parent
reply
40 points
*

JSON has types.

Many API developers may choose not to use them, but they are absolutely there.

You specify the type by including or excluding quotation marks, and then for the types without quotation marks, you either include or exclude a decimal point to specify float or integer, and for boolean you use characters (specifically true or false). Arrays are wrapped in [] and objects are wrapped in {}.

JSON data as a whole is passed as one giant string because the REST protocol demands it. But once it’s been pulled in and properly interpreted, there are absolutely types in the data.

permalink
report
reply
0 points

Great post, but I have to “well, actually” you on this little thing:

the REST protocol demands it.

REST is not a protocol, and does not have to do anything with JSON.

(eg. How Did REST Come To Mean The Opposite of REST? by Carson Gross)

permalink
report
parent
reply
17 points
*

Wait, some people don’t know that??? It’s literally called “JavaScript Object Notation”.

permalink
report
parent
reply
12 points

Absolutely. Who doesn’t type JSON?

permalink
report
parent
reply
1 point
*

I’m not sure if i’m missing a joke here, so:

In case you’re making a joke: The people who don’t type JSON are using controllers.

In case you’re asking a serious question: the people who don’t type JSON are the people in OP’s image. They are technically using types, but that type is literally always string. They don’t use integers, they don’t use booleans. This is functional but may not be the best choice, depending on what kinds of data their system is supposed to handle.

permalink
report
parent
reply
1 point

Would you mind elaborating a bit for someone who doesn’t do much coding? I’m guessing I’m one of the people you’re talking about.

The only coding I’ve done has been via json for raspberry pi, 3d printer, and homeassistant applications.

I know it’s a text base language, but how do it’s commands relate to integers? I’ve used boolean, I get that bit.

permalink
report
parent
reply
7 points
*

We aren’t using json.atChar(17) to get values?

permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 6.2K

    Monthly active users

  • 775

    Posts

  • 6.8K

    Comments

Community moderators