-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Minor Change
The libsson function bson_as_json does not properly serialize the extended JSON type Code.
The expected behavior is to output an object with "$code" and "$scope" attributes as demonstrated by json_util from PyMongo
>>> import bson >>> from bson import json_util >>> from bson.code import Code >>> json_util.dumps({"code": Code("function x() { return 1; }")}) '{"code": {"$code": "function x() { return 1; }", "$scope": {}}}' >>> b = bson.BSON.encode({"code": Code("function x() { return 1; }")}) >>> b '*\x00\x00\x00\rcode\x00\x1b\x00\x00\x00function x() { return 1; }\x00\x00' >>> import bjson >>> bjson.dumps(b) '{ "code" : "function x() { return 1; }" }' >>>
bjson.dumps is a thin wrapper around bson_as_json using the Python C API.
- duplicates
-
CDRIVER-1364 BSON type "JavaScript code w/ scope" cannot be reliably roundtripped
- Closed
-
CDRIVER-1878 bson_append_code_with_scope drops empty scope
- Closed
- is related to
-
CDRIVER-1364 BSON type "JavaScript code w/ scope" cannot be reliably roundtripped
- Closed
- related to
-
CDRIVER-1695 libbson's bson-to-json does't allow for round tripping of Javascript type
- Closed
-
PHPC-459 BSON objects should implement JsonSerializable
- Closed
-
CDRIVER-1879 libbson truncates code_with_scope with embedded nulls in javascript
- Closed
-
PHPC-714 Implement BSON corpus test suite
- Closed
-
CDRIVER-1913 Parse "$code" extended JSON
- Closed