[CDRIVER-1695] libbson's bson-to-json does't allow for round tripping of Javascript type Created: 13/Oct/16  Updated: 27/Oct/16  Resolved: 27/Oct/16

Status: Closed
Project: C Driver
Component/s: json
Affects Version/s: 1.5.0
Fix Version/s: 1.5.0

Type: Bug Priority: Major - P3
Reporter: Derick Rethans Assignee: Backlog - C Driver Team
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-1364 BSON type "JavaScript code w/ scope" ... Closed
is related to CDRIVER-1335 libbson does not properly serialize t... Closed

 Description   

libbson's bson-to-json converts the BSON Javascript type to just:

{ "foo" : "function foo(bar) { return bar; }" }

(Document with single ```foo``` key).

On the way from json-to-bson, there is no way to distinguish this from a (key => string) pair, and hence, libbson does not create a BSON Javascript type.

I would suggest to use the "extended JSON"'s serialisation way:

    "CodeWithScope": {
        "$code": "function(){}",
        "$scope": {}
    },



 Comments   
Comment by Bernie Hackett [ 13/Oct/16 ]

Though it's not documented at https://docs.mongodb.com/manual/reference/mongodb-extended-json/, the extended JSON format for CodeWScope is:

{“$code”: <string>, “$scope”: <document>}

There is no "CodeWithScope" key in the output.

Generated at Wed Feb 07 21:13:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.