Skip to content

cmd/marcconv: stream MARC21 records between marc/xml/json/text - #1

Draft
beyto1974 wants to merge 2 commits into
masterfrom
worktree-marcconv-cli
Draft

beyto1974 wants to merge 2 commits into
masterfrom
worktree-marcconv-cli

Conversation

@beyto1974

Copy link
Copy Markdown
Owner

Summary

  • Adds cmd/marcconv, a CLI that streams MARC21 records between binary MARC, MARCXML, and MARC-in-JSON (and out to MARCMaker text), converting one record at a time.
  • Adds a streaming JSONReader in marcjson.go so JSON input can be decoded record-by-record like the existing binary Reader/XMLReader, instead of requiring ParseJSON's whole-document slurp. Refactors sanitizeLenientJSON to reuse the same streaming control-character filter.
  • -from/-to are guessed from file extensions (.mrc/.marc/.dat, .xml, .json, .txt) when not given explicitly; required when reading from stdin.

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l . (clean)
  • go test ./... (112 passed)
  • Manual smoke test: marc → xml → json → marc round trip via marcconv, verified identical MARCMaker text output (leader byte 9 correctly flips to reflect MARC-8 → Unicode transcoding, per spec)
  • Manual smoke test: stdin/stdout with explicit -from/-to, -o extension-based format guessing, missing -from on stdin exits with usage error

🤖 Generated with Claude Code

beyto1974 and others added 2 commits July 25, 2026 06:32
Adds a streaming JSONReader (marcjson.go) alongside the existing binary
Reader and XMLReader, so all three input formats can be decoded one
record at a time instead of requiring ParseJSON's whole-document slurp.
cmd/marcconv is a new CLI built on the shared Next()/Write() shape of
these readers/writers, converting -from one format -to another (formats
guessed from file extensions when not given explicitly).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
flag.Parse stops scanning at the first non-flag argument, so the exact
usage shown in the README ("marcconv in.dat -o out.json") was rejected
with a usage error — -o and its value were misread as extra positional
args. Reorder recognized flag tokens ahead of positionals before parsing
so flags work regardless of where they sit relative to the input file.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant