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

  • frezik@midwest.social
    link
    fedilink
    arrow-up
    2
    ·
    4 months 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
      5
      ·
      4 months 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