Skip to content

📤 Export Formats

The cpeskills package provides functions to serialize vulnerability reports and SBOMs into industry-standard interchange formats: JSON, CSV, SARIF, CycloneDX and SPDX.

Type: ExportFormat

go
type ExportFormat string

A string enum selecting the output format for vulnerability report exports.

Constants

ConstantTypeValueDescription
ExportFormatJSONExportFormat"json"JSON format
ExportFormatCSVExportFormat"csv"CSV format
ExportFormatSARIFExportFormat"sarif"SARIF format (Static Analysis Results Interchange Format)
go
_ = cpeskills.ExportFormatJSON
_ = cpeskills.ExportFormatCSV
_ = cpeskills.ExportFormatSARIF

📄 ExportVulnerabilityReport

go
func ExportVulnerabilityReport(report *VulnerabilityReport, format ExportFormat) ([]byte, error)

Exports a single vulnerability report to the specified format. Dispatches to the corresponding format-specific exporter.

ParameterTypeDescription
report*VulnerabilityReportThe report to export
formatExportFormatThe target format
ReturnTypeDescription
#1[]byteThe serialized report bytes
#2errorAn error if the format is unsupported or serialization fails
go
data, err := cpeskills.ExportVulnerabilityReport(report, cpeskills.ExportFormatJSON)
if err != nil {
    log.Fatal(err)
}
fmt.Println(string(data))

🔷 ExportToJSON

go
func ExportToJSON(report *VulnerabilityReport) ([]byte, error)

Exports a vulnerability report as pretty-printed JSON (2-space indented).

ParameterTypeDescription
report*VulnerabilityReportThe report to export
ReturnTypeDescription
#1[]byteThe JSON bytes
#2errorAn error if report is nil or marshaling fails
go
data, err := cpeskills.ExportToJSON(report)

📊 ExportToCSV

go
func ExportToCSV(reports []*VulnerabilityReport) ([]byte, error)

Exports multiple vulnerability reports as CSV. The header row is Component, Version, CVE, Severity, CVSS, EPSS, KEV, Reachability, FixAvailable, FixedVersion, followed by one row per vulnerability finding.

ParameterTypeDescription
reports[]*VulnerabilityReportThe reports to export
ReturnTypeDescription
#1[]byteThe CSV bytes
#2errorAn error if writing fails
go
data, err := cpeskills.ExportToCSV(reports)

🛡️ ExportToSARIF

go
func ExportToSARIF(reports []*VulnerabilityReport) ([]byte, error)

Exports vulnerability reports as SARIF 2.1.0, the OASIS standard static-analysis results interchange format supported by GitHub and Azure DevOps. Critical/High severities map to error, Medium to warning, others to note.

ParameterTypeDescription
reports[]*VulnerabilityReportThe reports to export
ReturnTypeDescription
#1[]byteThe SARIF JSON bytes
#2errorAn error if marshaling fails
go
data, err := cpeskills.ExportToSARIF(reports)

🔄 ExportSBOMToCycloneDX

go
func ExportSBOMToCycloneDX(sbom *SBOM) ([]byte, error)

Exports an SBOM to CycloneDX JSON format (delegates to sbom.ToCycloneDXJSON()).

ParameterTypeDescription
sbom*SBOMThe SBOM to export
ReturnTypeDescription
#1[]byteThe CycloneDX JSON bytes
#2errorAn error if serialization fails
go
data, err := cpeskills.ExportSBOMToCycloneDX(sbom)

📋 ExportSBOMToSPDX

go
func ExportSBOMToSPDX(sbom *SBOM) ([]byte, error)

Exports an SBOM to SPDX JSON format (delegates to sbom.ToSPDXJSON()).

ParameterTypeDescription
sbom*SBOMThe SBOM to export
ReturnTypeDescription
#1[]byteThe SPDX JSON bytes
#2errorAn error if serialization fails
go
data, err := cpeskills.ExportSBOMToSPDX(sbom)

📦 ExportVulnerabilityReportBatch

go
func ExportVulnerabilityReportBatch(reports []*VulnerabilityReport, format ExportFormat) ([]byte, error)

Exports a batch of vulnerability reports in the specified format. For JSON it marshals the whole slice; for CSV/SARIF it delegates to the corresponding batch exporters.

ParameterTypeDescription
reports[]*VulnerabilityReportThe reports to export
formatExportFormatThe target format
ReturnTypeDescription
#1[]byteThe serialized bytes
#2errorAn error if the format is unsupported or serialization fails
go
data, err := cpeskills.ExportVulnerabilityReportBatch(reports, cpeskills.ExportFormatCSV)

🧭 Export Dispatch

Released under the MIT License.