ndjson

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ndjson implements newline-delimited JSON as a codec.Codec. Each record is a JSON value followed by a single '\n' — the format is intentionally line-oriented so that partial reads remain parseable. The codec accepts slice values: Marshal emits one record per element, Unmarshal splits on '\n' and decodes each non-empty line into a new slice element.

Package ndjson — range 0.3.11.* (ADR 0005 service/codec/ndjson block).

Package ndjson — declares the sentinel *errs.Error values for NDJSON.

Index

Constants

View Source
const CodeNDJSONMarshalFailed errs.Code = 0x00_03_0B_01 // 0.3.11.1

CodeNDJSONMarshalFailed identifies a failure inside encoding/json.Marshal when encoding a single NDJSON record.

View Source
const CodeNDJSONUnmarshalFailed errs.Code = 0x00_03_0B_02 // 0.3.11.2

CodeNDJSONUnmarshalFailed identifies a failure inside encoding/json.Unmarshal when decoding a single NDJSON record.

View Source
const CodeNDJSONValueInvalid errs.Code = 0x00_03_0B_03 // 0.3.11.3

CodeNDJSONValueInvalid identifies a Marshal / Unmarshal call whose target is not a slice (NDJSON models a stream of records).

Variables

View Source
var (
	// MarshalFailed wraps a failure from encoding/json.Marshal on a single record.
	MarshalFailed = errs.Define(CodeNDJSONMarshalFailed, "MARSHAL_FAILED",
		"NDJSON encoding failed",
		"service/codec/ndjson: encoding/json.Marshal returned an error on a record")

	// UnmarshalFailed wraps a failure from encoding/json.Unmarshal on a single record.
	UnmarshalFailed = errs.Define(CodeNDJSONUnmarshalFailed, "UNMARSHAL_FAILED",
		"NDJSON decoding failed",
		"service/codec/ndjson: encoding/json.Unmarshal returned an error on a record")

	// ValueInvalid fires when the caller does not pass a slice target.
	ValueInvalid = errs.Define(CodeNDJSONValueInvalid, "VALUE_INVALID",
		"NDJSON codec requires a slice target",
		"service/codec/ndjson: Marshal/Unmarshal called with a non-slice argument")
)
View Source
var (
	//: register the singleton and expose it as a typed package var.
	Codec codec.Codec = codec.Register(&ndjsonCodec{})
)

Package-level state: the codec singleton plus the hoisted MIME / extension tables (hoisted).

Functions

func New

func New() codec.Codec

New returns an NDJSON codec instance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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