jsonl

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

Linear JSON Tools for Go

This repository contains an initial set of tools to work with linear JSON (jsonl) files and data. The first release of these modules includes Go functions focues on:

  1. Flattening JSON data
  2. Packing JSON structs into jsonl files
  3. Unpacking JSON structs from jsonl files

Install

go get github.com/carabiner-dev/jsonl

This module is copyright and released under the Apache 2.0 license by Carabiner Systems. We welcome contributions, bug reports and patches. Oh and also, let us know if you build something cool with it!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlattenJSON

func FlattenJSON(data []byte) ([]byte, error)

func FlattenJSONDirectoryToWriter

func FlattenJSONDirectoryToWriter(w io.Writer, path string) error

FlattenJSONDirectoryToWriter flattens all JSON files in a directory

func FlattenJSONStream

func FlattenJSONStream(r io.Reader) io.Reader

FlattenJSON flattens a JSON document into a single line, suitable to add to a jsonl file.

func IterateBundle added in v0.2.0

func IterateBundle(r io.Reader) iter.Seq2[int, io.Reader]

IterateBundle implements an iterator that returns an io.Reader for each json file contained in a bundle read from reader r. The iteraror will loop exactly once for each line in the file.

If a line contains data which cannot be parsed as json, the iterator will still loop but instead of an io.Reader the value will be nil.

func PackFilesToBundle

func PackFilesToBundle(bundle string, paths []string) error

PackFilesToStream takes a writer and writes to it the flattened versions of the JSON files passed in the paths

func PackFilesToStream

func PackFilesToStream(w io.Writer, paths []string) error

PackFilesToStream takes a writer and writes to it the flattened versions of the JSON files passed in the paths

func UnpackBundle

func UnpackBundle(r io.Reader, fnOpts ...unpackoptFunc) error

UnpackBundle reads data from the r io.Reader and writes each json document to a separate file.

func UnpackBundleFile

func UnpackBundleFile(path string, fnOpts ...unpackoptFunc) error

UnpackBundleFile reads a jsonl file and extracts attestations bundled in it.

func WithFailOnInvalid

func WithFailOnInvalid(yesno bool) unpackoptFunc

WithFailOnInvalid makes the extractor fail if there is an unparseable line

func WithFilePrefix

func WithFilePrefix(prefix string) unpackoptFunc

WithFilePrefix specifies a prefix to use in the filenames

func WithOutputDirectory

func WithOutputDirectory(path string) unpackoptFunc

WithFilePrefix specifies a prefix to use in the filenames

Types

This section is empty.

Jump to

Keyboard shortcuts

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