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

  • fibojoly@sh.itjust.works
    link
    fedilink
    arrow-up
    7
    arrow-down
    1
    ·
    1 day ago

    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

  • neclimdul@lemmy.world
    link
    fedilink
    arrow-up
    20
    arrow-down
    1
    ·
    2 days ago

    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.

    • cm0002@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      21 hours ago

      “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

      • neclimdul@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        21 hours ago

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

  • Semperverus@lemmy.world
    link
    fedilink
    English
    arrow-up
    33
    ·
    edit-2
    2 days ago

    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.

    • slimarev92@lemmy.world
      link
      fedilink
      arrow-up
      15
      arrow-down
      1
      ·
      edit-2
      2 days ago

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

      • Semperverus@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        1 day ago

        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.

        • Bach37strad@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          1 day ago

          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.

          • cm0002@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            21 hours ago

            When passing or storing data in code you usually have to specify what type of data is it. An int is an integer, so numbers, there’s also boolean (true/false) and many others. There’s also string which is just characters of any kind (for the most part) which pretty much makes it a catch-all, since numbers can be a string along with letters and special characters.

            But to use a number as a number after it’s been received as a string it has to be converted to an int, which means extra code, more effort, more failure points etc etc.

    • flamingo_pinyata@sopuli.xyz
      link
      fedilink
      arrow-up
      24
      ·
      edit-2
      2 days ago

      Just reminded me of an argument trying to explain that arithmetic with floating point numbers is not always correct to a coworker who was a mathematician just starting in software dev.

      In a mathematicians mind the fact that an arithmetic operation can produce inaccurate result is just incomprehensible

      • Scrubbles@poptalk.scrubbles.tech
        link
        fedilink
        English
        arrow-up
        14
        ·
        2 days ago

        The fun differences between the perfect world of theoretical and the realistic. Everyone thinks of computers as perfect - but it’s not until you’re asked to solve “How do you store decimals using only 0s and 1s?” does it start to click. Not as easy. It’s why I’m hesitant to hire bootcampers into my roles. Bootcamps are great, and they get more people coding, but you don’t learn that theory behind the scenes - you don’t really know what the computer and operating systems are doing. For 90% of the time it doesn’t matter, it’s abstracted away - but that last 10% man, that can really fuck up an entire system.

    • andyburke@fedia.io
      link
      fedilink
      arrow-up
      9
      ·
      edit-2
      2 days ago

      You are a fintech dev using floating point? And your advice is to encode things as strings?

      This is why I got out of fintech.

      (I am sorry, I know there are horrors and I am sure I am not familiar with your exact scenario.)

      Edit: just for anyone who passes by: try to stick with integers in a currency’s smallest unit of division. (This is only one small bit of this problem, but the number of times I have seen currency values in floating point makea me psychotic.)

      • bleistift2@sopuli.xyzOP
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 day ago

        try to stick with integers in a currency’s smallest unit of division

        And then the marketing department comes up with products that cost 1.5ct apiece.

      • Scrubbles@poptalk.scrubbles.tech
        link
        fedilink
        English
        arrow-up
        7
        ·
        2 days ago

        Until you get to multi currency, which is why I don’t support using ints or longs, and strings are still the only way. There are currencies that have no precision, and others that have 3 or more digits of precision - and then you’re looking at doing calculations each time. Strings are the safest way to make sure you’re representing exactly what you want to when sending data over the wire or persisting

    • frezik@midwest.social
      link
      fedilink
      arrow-up
      2
      ·
      2 days ago

      JSON numeric encoding is perfectly capable of precise encoding to arbitrary decimal precision. Strings are easier if you don’t want to fuck around with the parser, though.

      • Scrubbles@poptalk.scrubbles.tech
        link
        fedilink
        English
        arrow-up
        4
        ·
        2 days ago

        Correct, JSON can handle any precision, because it’s just dumped as a string anyway, just not enclosed in the "". However, as you mentioned, as soon as it comes through the parser it’ll put it into an underlying float value. In C# I create a save high precision attribute that will take the value and put it directly into a decimal. In JS I’m sure there’s some way to do that, but that parser is way less extensible compared to C#. However, this also all assumes you know the client will parse it correctly, overriding the default behavior. Safest is to just send it as a string, and then create your parsers to automatically send to and from strings

  • PeriodicallyPedantic@lemmy.ca
    link
    fedilink
    arrow-up
    17
    arrow-down
    1
    ·
    2 days ago

    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 😭

    • bleistift2@sopuli.xyzOP
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      1
      ·
      1 day ago

      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?

  • ShortFuse@lemmy.world
    link
    fedilink
    arrow-up
    6
    arrow-down
    1
    ·
    edit-2
    2 days ago

    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.

    • ApexHunter@lemmy.ml
      link
      fedilink
      arrow-up
      10
      ·
      2 days ago

      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)

      • Zucca@sopuli.xyz
        link
        fedilink
        arrow-up
        2
        arrow-down
        1
        ·
        1 day ago

        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?