-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: JSON
-
None
-
Java Drivers
So, given this code snippet:
var bson = BsonDocument.parse(someDocumentToParse); System.out.println(bson.toJson(JsonWriterSettings.builder() .indent(true) .outputMode(JsonMode.SHELL) .build()));
The driver will generate a String that resembles to the mongosh syntax. To give you an example input/output:
This:
var bson = BsonDocument.parse(""" { _id: { $oid: "5735040085629ed4fa839473" }, code: { $code: "{}" }, n: { $numberInt: '10000' }, l: { $numberLong: '1355875200000' }, d: { $numberDouble: '10.5' }, dec: { $numberDecimal: '10.99' }, lena: 'olya' }""" ); System.out.println(bson.toJson(JsonWriterSettings.builder() .indent(true) .outputMode(JsonMode.SHELL) .build()));
outputs:
{ "_id": ObjectId("5735040085629ed4fa839473"), "code": { "$code": "{}" }, "n": 10000, "l": NumberLong("1355875200000"), "d": 10.5, "dec": NumberDecimal("10.99"), "lena": "olya" }
This is the behaviour of mongosh:
mongosh test> EJSON.parse(`{ ... "_id": { "$oid": "5735040085629ed4fa839473" }, ... "code": { "$code": "{}" }, ... "n": { "$numberInt": "10000" }, ... "l": { "$numberLong": "1355875200000" }, ... "d": { "$numberDouble": "10.5" }, ... "dec": { "$numberDecimal": "10.99" }, ... "lena": "olya" ... }`) { _id: ObjectId('5735040085629ed4fa839473'), code: Code('{}'), n: 10000, l: 1355875200000, d: 10.5, dec: Decimal128('10.99'), lena: 'olya' }
- related to
-
COMPASS-7889 Pass schema with sample values
- Open