bson_to_json

Function bson_to_json 

Source
pub fn bson_to_json(value: &Bson) -> Result<Value>
Expand description

Convert a BSON value to JSON

Maps BSON types to JSON types:

  • Int32/Int64 → number
  • Double → number
  • String → string
  • Bool → boolean
  • Array → array
  • Document → object
  • ObjectId → object with $oid field
  • DateTime → object with $date field
  • Binary → object with $binary field (base64)
  • Null/Undefined → null

§Arguments

  • value - BSON value from MongoDB

§Returns

JSON value suitable for JSONB storage

§Examples

let bson_int = Bson::Int32(42);
let json = bson_to_json(&bson_int).unwrap();
assert_eq!(json, serde_json::json!(42));