this example demonstrates the layered dd i/o api: binding and unbinding JSON and YAML from bytes, readers/writers, and files, plus appending records to a JSON Lines stream.
key concepts demonstrated
three layers, one shape
bytes: dd.BindJSON/dd.BindYAML and dd.UnbindJSON/dd.UnbindYAML
readers and writers: dd.BindJSONReader/dd.BindYAMLReader and dd.UnbindJSONWriter/dd.UnbindYAMLWriter
files: dd.BindJSONFile/dd.BindYAMLFile and dd.UnbindJSONFile/dd.UnbindYAMLFile (dd.NewJSONFile[T]/dd.NewYAMLFile[T] allocate the target for you)
json lines
dd.UnbindJSONLWriter: one compact, newline-terminated record per call, appended to any io.Writer — open the file with O_APPEND and call it once per record
reading back: nothing new — bufio.Scanner plus dd.BindJSON per line
error handling
consistent dd error types across every layer: file errors, parse errors, and binding errors
workflow demonstrated
bytes layer: bind from JSON/YAML bytes, unbind back to bytes
reader/writer layer: the same through io.Reader and io.Writer
file layer: write config.json and config.yaml, read them back
jsonl record streams: append three records to events.jsonl, scan them back