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

bson_as_json outputs doubles as integers

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 1.6.0
    • 1.5.0
    • libbson
    • None

    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

        Activity

          People

            jesse@mongodb.com A. Jesse Jiryu Davis
            david.golden@mongodb.com David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: