MongoDB.JSONtoBSON
------------------

Converts JSON to BSON.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [MongoDB](component_MongoDB.md) | [12.3](newinversion123.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "MongoDB.JSONtoBSON"; JSON { ; FileName } ) 

**MBS**( **"MongoDB.JSONtoBSON";** /\* Converts JSON to BSON. \*/  
**$JSON**; /\* The JSON to convert. \*/   
**$FileName**) /\* Optional; The file name to use. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| JSON | The JSON to convert. |  |  |
| FileName | The file name to use. |  | Optional |

### Result

Returns FILE Container or error.

### Description

Converts JSON to BSON.  
Returns a container value with FILE entry containing BSON.  
You can use EncodeHex() to convert it to hex string if needed.  
### Examples

Encode a blank object:

 HexEncode ( MBS ( "MongoDB.JSONtoBSON"; "{}"))  
<small>  
Example result: 0500000000</small>Encode an array with string:

 HexEncode ( MBS ( "MongoDB.JSONtoBSON"; "\[\\"hello\\"\]"))  
### See also

- [MongoDB.BSONtoJSON](MongoDBBSONtoJSON.md)

This function checks for a license.

Created 22nd May 2022 , last changed 29th January 2023

  
[MongoDB.IsTracing](MongoDBIsTracing.md) - [MongoDB.Keys](MongoDBKeys.md)

[HTML Version](MongoDBJSONtoBSON.shtml)