Altova XMLSpy 2026 Enterprise Edition

Convert BSON to/from JSON/YAML

Home Prev Top Next

Make the JSON or YAML file that you want to convert to the other format the active file and select the Convert BSON to/from JSON/YAML command.

 

For the conversion in each direction, a dialog appears that enables you to select options for the conversion.

 

Note: This command is also available in the context menu of project folders. When used on a project folder, the command allows you to batch convert between JSON/YAML files and BSON files.

 

BSON to JSON/YAML conversion

On selecting the Convert command with a BSON file active, the following dialog appears.

ConvertBSON2JSONYAML

You can set various conversion options, as follows:

 

Output file format: The type of file to convert to (JSON, JSON5, JSON Lines, or YAML). The Auto option automatically selects the best output option on the basis of the structure and content of the BSON file.

 

Array for multiple roots: If the BSON document contains multiple root items—which is allowed in BSON, JSON Lines, and YAML, but not in JSON and JSON5—you can choose whether to wrap the multiple root items in a single array or not. (Note that if you do not generate an array for a JSON or JSON5 output document, multiple roots would render the document non-well-formed.)

 

Datatype format: You can choose between the Extended format, which preserves BSON type information in the output document, or the Simple format, in which JSON/YAML items are strings and BSON type information is not preserved. Note the following points by referring to the screenshot above: In the examples of the screenshot, the Simple format is more easily readable. Datatype information in Extended format documents is given in properties prefixed by $. If an Extended format document is converted back to BSON, then the datatype information stored in properties prefixed with $ can be used to generate the corresponding datatypes in BSON (see JSON/YAML to BSON Conversion below).

 

JSON/YAML to BSON conversion

On selecting the Convert command with a JSON or YAML file active, a dialog appears in which you can select the following options:

 

Accept and omit wrapping array at root level: This applies to JSON documents in which multiple roots have been wrapped in an array. If this option is selected (which is the default), then the array is omitted when converting to BSON and the BSON documents will have the multiple root items that are contained in the JSON document. (Multiple roots are allowed in BSON documents.)

Interpret object properties prefixed with $ as BSON type indicators: When BSON documents are converted to JSON/YAML (see BSON to JSON/YAML Conversion above), BSON type information that is unsupported in JSON/YAML is stored in properties indicated by a $ prefix. The current option enables such properties to be interpreted as BSON types when the JSON/YAML document is converted back to BSON.

 

© 2019-2025 Altova GmbH