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

  • brian@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    json doesn’t have ints, it has Numbers, which are ieee754 floats. if you want to precisely store the full range of a 64 bit int (anything larger than 2^53 -1) then string is indeed the correct type

    • bleistift2@sopuli.xyzOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      10 months ago

      json doesn’t have ints, it has Numbers, which are ieee754 floats.

      No. numbers in JSON have arbitrary precision. The standard only specifies that implementations may impose restrictions on the allowed values.

      This specification allows implementations to set limits on the range and precision of numbers accepted. Since software that implements IEEE 754 binary64 (double precision) numbers [IEEE754] is generally available and widely used, good interoperability can be achieved by implementations that expect no more precision or range than these provide, in the sense that implementations will approximate JSON numbers within the expected precision. A JSON number such as 1E400 or 3.141592653589793238462643383279 may indicate potential interoperability problems, since it suggests that the software that created it expects receiving software to have greater capabilities for numeric magnitude and precision than is widely available.

      https://www.rfc-editor.org/rfc/rfc8259.html#section-6

  • andyburke@fedia.io
    link
    fedilink
    arrow-up
    1
    ·
    10 months ago

    These JSON memes got me feeing like some junior dev out there is upset because they haven’t read and understood the docs.

    • bleistift2@sopuli.xyzOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      10 months ago

      Hell, no. If I wanted to save bytes, I’d use a binary format, or just fucking zip the JSON. Looking at a request-response pair and quickly understanding the transferred data is invaluable.

    • 0x0@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      10 months ago

      If there are no humans in the loop, sure, like for data transfer. But for, e.g., configuration files, i’d prefer a text-based solution instead of a binary one, JSON is a nice fit.

        • bob_lemon@feddit.org
          link
          fedilink
          arrow-up
          1
          ·
          10 months ago

          Yaml is just arcane bullshit to actually write as a human. Nor is it intuitively clear how yaml serializes.

        • bitfucker@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          10 months ago

          Until someone cannot tell the difference between tab and space when configuring or you miss one indentation. Seriously, whoever thinks indentation should have semantic meaning for computers should burn in hell. Indentation is for us, humans, not computers. You can write a JSON with or without indentation if you want. Also, use JSON5 to have comments and other good stuff for a config file.

        • wtfrank@feddit.uk
          link
          fedilink
          English
          arrow-up
          0
          ·
          10 months ago

          Fine, and if you don’t use json in your API because of the deficiency highlighted in the meme, what format do you use in your API?

          • JackbyDev@programming.dev
            link
            fedilink
            English
            arrow-up
            1
            ·
            10 months ago

            I use JSON. I have used Avro for things in Kafka but I’m not sure the benefits outweigh the negatives. Avro is much more complicated than people think and most folks don’t really have a strong desire to learn how it should be used and do stuff incorrectly. Everybody knows JSON and it works with everything though. (Example: so many people just hear that Avro schemas can be backwards compatible but have zero idea that you still need the schema that wrote the message even if you want to read it into a newer one.)

            Interestingly, I take the meme as saying a dev is using the wrong types in their serialization format (using strings to store integers) which was my biggest problem with Avro. Mostly from people not using logical types or preferring to use ISO 8601 datetime strings instead of the built-in timestamp-millis type.

  • RustyNova@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    10 months 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
      link
      fedilink
      arrow-up
      0
      ·
      10 months 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.

      • Ethan@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        10 months 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.

    • skuzz@discuss.tchncs.de
      link
      fedilink
      arrow-up
      0
      ·
      10 months ago

      “Hey, it appears to be int most of the time except that one time it has letters.”

      throws keyboard in trash