format

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExtension

func GetExtension(format string) string

GetExtension returns the file extension for the format

func JSONToYAML

func JSONToYAML(jsonData []byte) ([]byte, error)

JSONToYAML converts JSON data to YAML

func PrettyJSON

func PrettyJSON(jsonData []byte) ([]byte, error)

PrettyJSON formats JSON with indentation

func PrettyYAML

func PrettyYAML(yamlData []byte) ([]byte, error)

PrettyYAML formats YAML with proper indentation

func ValidateAndConvert

func ValidateAndConvert(data []byte) ([]byte, error)

ValidateAndConvert validates input data and converts it to JSON It auto-detects the format and converts YAML to JSON if needed

func YAMLNodeFromJSON

func YAMLNodeFromJSON(v any) (any, error)

YAMLNodeFromJSON renders a value through its JSON representation so that yaml.Marshal produces output structurally identical to json.Marshal.

It is the canonical implementation for a type's MarshalYAML when the type relies on JSON struct tags for its wire shape (json:"-" to hide display-only fields, omitempty, camelCase keys) and/or embeds []byte or json.RawMessage fields. Without it, yaml.v3 falls back to reflection: struct tags are ignored (keys are lowercased, omitempty is not honored, json:"-" fields leak in) and []byte/json.RawMessage fields are emitted as a sequence of raw byte values.

Numbers keep their JSON token: decoding them into float64 would round an integer above 2^53, and a document printed with `-o yaml` and applied back must carry the value the server sent.

json.Marshal never invokes MarshalYAML, so calling this from a MarshalYAML method does not recurse.

func YAMLToJSON

func YAMLToJSON(yamlData []byte) ([]byte, error)

YAMLToJSON converts YAML data to JSON

Types

type Format

type Format string

Format represents the data format

const (
	FormatJSON Format = "json"
	FormatYAML Format = "yaml"
)

func DetectFormat

func DetectFormat(data []byte) (Format, error)

DetectFormat auto-detects whether the data is JSON or YAML

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL