jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
286 stars 65 forks source link

Moves to canonical extended JSON output #147

Closed atheriel closed 6 years ago

atheriel commented 6 years ago

As discussed in jeroen/jsonlite#247, mongolite is currently producing so-called "legacy" extended JSON in some places. This commit moves existing uses of bson_as_json() to bson_as_canonical_extended_json() in an effort to resolve this.

jeroen commented 6 years ago

Hmm I really don't like that the new spec wraps every integer and number is now wrapped in another object. This creates a lot of overhead, and in R we rarely distinguish these types.

   "Int32": {
       "$numberInt": "42"
   },
   "Int64": {
       "$numberLong": "42"
   },
   "Double": {
       "$numberDouble": "42.42"
   },

If we switch I think I would prefer the 'relaxed' extended json.

atheriel commented 6 years ago

Do you mean in terms of the R objects generated? If so, I definitely favour efficiency. Otherwise I think this change only applies to generating JSON strings -- and there it might make more sense to favour correctness.

jeroen commented 6 years ago

I really don't like how inserting some data from R and then exporting it blows up the json because each value is wrapped in "$numberDouble": "42.42". This blows up the format and kills the interoperability, which defeats the purpose of JSON.

Generally I don't think R users care about this. In R all numbers get silently coerced to doubles. Hence I prefer the "relaxed" format which I think is more in line with the R philosophy.

atheriel commented 6 years ago

Makes sense to me. :+1: