Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-1945

bson_as_json outputs doubles as integers

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 1.5.0
    • Fix Version/s: 1.6.0
    • Component/s: libbson
    • Labels:
      None
    • Sprint:
      C Driver 2017 1 - Jan 20, 2017

      Description

      Example code:

      #include <bson.h>
      #include <stdio.h>
       
      int main() {
          bson_t b = BSON_INITIALIZER;
          BSON_APPEND_DOUBLE (&b, "a", 1.0);
       
          size_t len;
          char *str;
          str = bson_as_json (&b, &len);
          printf ("%s\n", str);
       
          bson_free (str);
          return 0;
      }
      

      Actual output:

      { "a" : 1 }
      

      Possibly expected output:

      { "a" : 1.0 }
      

      Some JSON encoders will preserve a fractional part of zero. This behavior surprised as least one user as shown on this stack overflow post.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: