(python2.6) ➜ python-bsonjs git:(master) ✗ python
|
Python 2.6.9 (unknown, Oct 23 2015, 19:19:20)
|
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
|
Type "help", "copyright", "credits" or "license" for more information.
|
>>> import bsonjs
|
>>> print(bsonjs.loads.__doc__)
|
load(json) -> bytes
|
|
Encode `json` (a `str` or `bytes-like object` containing a MongoDB Extended
|
JSON document) to BSON bytes.
|
This function wraps `bson_init_from_json` from libbson.
|
>>> bsonjs.loads('{"$numberLong": "1"}')
|
Traceback (most recent call last):
|
File "<stdin>", line 1, in <module>
|
ValueError: Invalid MongoDB extended JSON
|
>>> bsonjs.loads('{"$numberLong": "1", "a": 1}')
|
Traceback (most recent call last):
|
File "<stdin>", line 1, in <module>
|
ValueError: Invalid key a": 1}. Looking for values for 18
|
>>> bsonjs.loads('{"a": 1, "$numberLong": "1"}')
|
'\x1f\x00\x00\x00\x10a\x00\x01\x00\x00\x00\x02$numberLong\x00\x02\x00\x00\x001\x00\x00'
|
>>> bsonjs.loads('{"a": 1, "$numberLong": "1", "a": 1}')
|
'&\x00\x00\x00\x10a\x00\x01\x00\x00\x00\x02$numberLong\x00\x02\x00\x00\x001\x00\x10a\x00\x01\x00\x00\x00\x00'
|