mongodb-labs / python-bsonjs

A fast BSON to MongoDB Extended JSON converter for Python - This Repository is NOT a supported MongoDB product
Apache License 2.0
40 stars 10 forks source link

Saving a list object loads as a dictionary #13

Closed dzimbeck closed 2 years ago

dzimbeck commented 6 years ago

if you do the following: bsonjs.loads(json.dumps([]))

The result is {}

This caused some minor issues in a program I'm working on. Since json is able to load lists I think there is no reason bson shouldn't experience similar behavior.

ShaneHarvey commented 6 years ago

Thanks @dzimbeck this is indeed surprising. I suspect this is a bug in libbson that might be fixed in the latest release. This project uses libbson 1.6.2 and the current release is 1.11.0, http://mongoc.org/libbson/current/index.html.

Once we update for Extend JSON v2.0 support in #11 I'll come back to this issue.

behackett commented 2 years ago

@juliusgeo this should be resolved by updating to the latest version of libbson.

juliusgeo commented 2 years ago

This issue does not seem to be solved by the latest version of libbson (1.20.0).

Python 3.8.9 (default, Aug 21 2021, 15:53:23) 
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsonjs
>>> import json
>>> import bson
>>> bson.decode(bsonjs.loads(json.dumps([])))
{}

This is after running pip install -e . on the master branch of python-bsonjs

juliusgeo commented 2 years ago

PR (#37 ) resolved this issue by documenting the behavior and illustrating a workaround for it in the README.