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

bson_as_json outputs doubles as integers

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.6.0
    • Affects Version/s: 1.5.0
    • Component/s: libbson
    • Labels:
      None

      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.

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

              Created:
              Updated:
              Resolved: