ndjson

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

README

JSON Lines

Documentation and specification for the JSON Lines text file format

Note: the following three terms are all equivalent formats, but for
now I will use the term JSON Lines. The equivalent formats are:

  • Line delimited JSON (LDJSON)
  • Newline delimited JSON (NDJSON)
  • JSON Lines (JSONL)

*More information can be found at jsonlines.org or at ndjson.org

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedEOF    = errors.New("unexpected EOF")
	ErrKeyNotFound      = errors.New("key not found")
	ErrIndexOutOfBounds = errors.New("index out of bounds")
	ErrToLessThanFrom   = errors.New("to index less than from index")
	ErrUnexpectedValue  = errors.New("unexpected value")
)
View Source
var (
	ErrPtrRequired        = errors.New("pointer required")
	ErrPtrToSliceRequired = errors.New("pointer is not pointing to a slice")
)

Functions

func Any

func Any(in []byte, pos int) (int, error)

Any returns the position of the end of the current element that begins at pos; handles any valid json element

func Array

func Array(in []byte, pos int) (int, error)

Array returns the position of the end of the array that begins at the position specified

func AsArray

func AsArray(in []byte, pos int) ([][]byte, error)

AsArray accepts an []byte encoded json array as an input and returns the array's elements

func Boolean

func Boolean(in []byte, pos int) (int, error)

Boolean matches a boolean at the specified position

func Expect

func Expect(in []byte, pos int, content ...byte) (int, error)

func FindIndex

func FindIndex(in []byte, pos, index int) ([]byte, error)

FindIndex accepts a JSON array and return the value of the element at the specified index

func FindKey

func FindKey(in []byte, pos int, k []byte) ([]byte, error)

FindKey accepts a JSON object and returns the value associated with the key specified

func FindRange

func FindRange(in []byte, pos, from, to int) ([]byte, error)

FindRange finds the elements of an array between the specified indexes; inclusive

func Match

func Match(data, pattern []byte, expected int) bool

func NewError

func NewError(pos int, b byte) error

func Null

func Null(in []byte, pos int) (int, error)

Null verifies the contents of bytes provided is a null starting as pos

func Number

func Number(in []byte, pos int) (int, error)

Number returns the end position of the number that begins at the specified pos

func Object

func Object(in []byte, pos int) (int, error)

Object returns the position of the end of the object that begins at the specified pos

func SkipSpace

func SkipSpace(in []byte, pos int) (int, error)

func String

func String(in []byte, pos int) (int, error)

String returns the position of the string that begins at the specified pos

Types

type LineReader

type LineReader struct {
	// contains filtered or unexported fields
}

LineReader reads one complete JSON document from each line.

func NewLineReader

func NewLineReader(r io.Reader) *LineReader

NewLineReader returns a reader that reads newline delimited JSON documents.

func (*LineReader) Read

func (lr *LineReader) Read(ptr interface{}) error

Decode decodes the next JSON document from the reader. It will return an error of io.EOF when the end of the file or stream is reached. The reader can continue to read lines even if the previous line returned and error (as long as the error is not io.EOF of course.)

func (*LineReader) ReadAll

func (lr *LineReader) ReadAll(v interface{}) (int, error)

ReadAll reads and unmarshalls all the json entries

func (*LineReader) ReadAllMatch

func (lr *LineReader) ReadAllMatch(pattern string, v interface{}) (int, error)

ReadAllMatch reads and unmarshalls all the json entries that match the provided patter

func (*LineReader) ReadAllRaw

func (lr *LineReader) ReadAllRaw() ([][]byte, error)

func (*LineReader) ReadAllRawMatch

func (lr *LineReader) ReadAllRawMatch(pattern string) ([][]byte, error)

func (*LineReader) ReadRaw

func (lr *LineReader) ReadRaw() ([]byte, error)

type LineWriter

type LineWriter struct {
	// contains filtered or unexported fields
}

func NewLineWriter

func NewLineWriter(w io.Writer) *LineWriter

func (*LineWriter) Write

func (lw *LineWriter) Write(v interface{}) (int, error)

Write writes data as a JSON document followed by a newline delimiter.

func (*LineWriter) WriteRaw

func (lw *LineWriter) WriteRaw(data []byte) (int, error)

WriteRaw writes data followed by a newline delimiter. It sanitizes the data and removes any newline characters before it finally writes.

type OpErr

type OpErr struct {
	Pos     int
	Msg     string
	Content string
}

func (OpErr) Error

func (o OpErr) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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