jsonl

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package jsonl provides utilities for reading and writing JSONL (JSON Lines) files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendOne

func AppendOne(path string, v any) error

AppendOne appends a single JSON object to a JSONL file.

func ReadAll

func ReadAll[T any](path string) ([]T, error)

ReadAll reads all objects from a JSONL file into a slice. The factory function creates new instances for each line.

Types

type FileWriter

type FileWriter struct {
	*Writer
	// contains filtered or unexported fields
}

FileWriter writes JSONL to a file with append support.

func OpenFile

func OpenFile(path string) (*FileWriter, error)

OpenFile opens or creates a JSONL file for appending.

func (*FileWriter) Close

func (fw *FileWriter) Close() error

Close closes the underlying file.

func (*FileWriter) Sync

func (fw *FileWriter) Sync() error

Sync flushes the file to disk.

type Reader

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

Reader reads JSON objects from a newline-delimited JSON stream.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader creates a new JSONL reader.

func (*Reader) Decode

func (r *Reader) Decode(v any) error

Decode decodes the next JSON object into v. Returns io.EOF when done.

func (*Reader) Err

func (r *Reader) Err() error

Err returns any error encountered during scanning.

func (*Reader) Next

func (r *Reader) Next() []byte

Next returns the next line as raw JSON bytes. Returns nil when done or on error.

type Writer

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

Writer writes JSON objects as newline-delimited JSON.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a new JSONL writer.

func (*Writer) Write

func (w *Writer) Write(v any) error

Write encodes and writes a single JSON object followed by a newline.

Jump to

Keyboard shortcuts

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