Documentation
¶
Overview ¶
Package marcjson reads and writes MARC 21 records in the de-facto "MARC-in-JSON" structure (the pymarc/ruby-marc/marc4j layout), implementing codex.RecordReader and codex.RecordWriter with a hand-rolled tokenizer (see scan.go) rather than encoding/json, so both directions avoid reflection and most per-token allocation.
A record is a JSON object with a "leader" string and an ordered "fields" array. Each field is a single-key object whose key is the 3-character tag: a control field maps the tag to a string value, while a data field maps it to an object with "ind1"/"ind2" strings and an ordered "subfields" array of single-key {code: value} objects:
{"leader":"…","fields":[
{"001":"ocm12345"},
{"245":{"ind1":"1","ind2":"0","subfields":[{"a":"Title"},{"c":"Author"}]}}
]}
Decoding walks JSON tokens (no reflection), preserving field and subfield order, and accepts a single object, a whitespace-separated stream of objects, or a top-level array. A Writer emits a JSON array and must be closed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
Encode serializes a record as a single compact MARC-in-JSON object. It returns an error if a value is not valid UTF-8 (which JSON cannot represent).
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads MARC records from a MARC-in-JSON stream one record at a time. It accepts a single object, a whitespace-separated stream of objects, or a top-level array of objects.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer streams records into a JSON array. Close must be called to emit the closing "]" and complete the document.