# Outputting

Once you have an instance of a `cyclonedx.model.bom.Bom` you can produce output in either JSON or XML against any of the supported CycloneDX schema versions.

We provide two helper methods:

- Output to string (for you to do with as you require)

- Output directly to a filename you provide

By default output will be in XML at latest supported schema version - see `cyclonedx.output.LATEST_SUPPORTED_SCHEMA_VERSION`.

## Supported CycloneDX Schema Versions

This library supports the following schema versions:

- 1.7 (XML, JSON) - the latest supported schema version

- 1.6 (XML, JSON)

- 1.5 (XML, JSON)

- 1.4 (XML, JSON)

- 1.3 (XML, JSON)

- 1.2 (XML, JSON)

- 1.0 (XML) - (note, 1.1 schema version has no support for JSON)

- 1.1 (XML) - (note, 1.1 schema version has no support for JSON)

## Outputting to JSON

The below example relies on the latest schema version, but sets the output format to JSON. Output is returned as a `str`.

    from cyclonedx.output import make_outputter, BaseOutput, OutputFormat, SchemaVersion

    outputter: BaseOutput = make_outputter(bom=bom, output_format=OutputFormat.JSON, schema_version=SchemaVersion.V1_7)
    bom_json: str = outputter.output_as_string()

Alternatively, if the output format and schema version are constants, you can use the predefined format+schema combined outputs:

    from cyclonedx.output.json import JsonV1Dot7

    outputter = JsonV1Dot7(bom=bom)
    bom_json: str = outputter.output_as_string()

## Outputting to XML

The below example relies on the default output format being XML, but overrides the schema version to 1.2. Output is written to the supplied filename.

    from cyclonedx.output import make_outputter, BaseOutput, OutputFormat, SchemaVersion

    outputter: BaseOutput = make_outputter(bom=bom, output_format=OutputFormat.XML, schema_version=SchemaVersion.V1_2)
    outputter.output_to_file(filename='/tmp/sbom-v1.2.xml')

Alternatively, if the output format and schema version are constants, you can use the predefined format+schema combined outputs:

    from cyclonedx.output.xml import XmlV1Dot2

    outputter = XmlV1Dot2(bom=bom)
    outputter.output_to_file(filename='/tmp/sbom-v1.2.xml')