Help us shape the future of Go! Take the 2026 Go Developer Survey

jsonio

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package jsonio reads JSON records — a JSON array of objects, or newline-delimited JSON (NDJSON, one object per line) — into gobi Frames. For GeoJSON, use geojsonio.

Each object is a row and each key a column, in first-seen order. A key missing from a row, or a JSON null, is a null cell. Parsing is encoding/json/jsontext (json v2) at its default strictness: a key repeated within one object, or invalid UTF-8, is an error. Numbers are kept as their literal text until the column's type is settled, so nothing is rounded through float64 on the way in.

Column types, from the column's non-null values:

  • all true/false: Boolean
  • all integers that fit int64: Int64 (an ID above 2^53 survives)
  • all numbers, some fractional or exponent-form: Float64, provided every integer in the column converts to float64 exactly
  • all strings: String
  • anything else — mixed kinds, an integer float64 can't hold exactly in an otherwise-Float64 column, integers beyond int64, numbers beyond float64, nested objects or arrays: String. Strings keep their value (no quotes); numbers, booleans and nested values become their JSON text (numbers as written, nested compacted). So [7, "a"] reads as "7" and "a".
  • no non-null values at all: String, every row null

ReadOptions.AllStrings skips inference and reads every column as String the same way.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotObject = errors.New("jsonio: record is not a JSON object")

ErrNotObject is returned when a record (an array element, or an NDJSON value) isn't a JSON object.

Functions

func Read

func Read(r io.Reader, opts *ReadOptions) (*gobi.Frame, error)

Read reads JSON records from r into a Frame. Every column is a single chunk. Empty input (or an empty array) gives a Frame with no columns and no rows. A Frame's row count comes from its columns, so input whose objects are all empty ({} per line) also reads as no columns and no rows.

Parsing uses encoding/json/jsontext with its default strictness: a key repeated within one object, or invalid UTF-8, is an error.

func ReadFile

func ReadFile(path string, opts *ReadOptions) (*gobi.Frame, error)

ReadFile reads the JSON records in path into a Frame.

Types

type Format

type Format uint8

Format selects the input layout.

const (
	// FormatAuto picks FormatArray when the first non-space byte is
	// '[' and FormatNDJSON otherwise.
	FormatAuto Format = iota
	// FormatArray is a single JSON array of objects.
	FormatArray
	// FormatNDJSON is a stream of objects, conventionally one per
	// line; any whitespace between objects is accepted.
	FormatNDJSON
)

type ReadOptions

type ReadOptions struct {
	// Format overrides input-layout detection.
	Format Format
	// AllStrings reads every column as String, with no inference:
	// strings as their value (no quotes), everything else as its JSON
	// text.
	AllStrings bool
	// Allocator overrides the Arrow allocator.
	Allocator memory.Allocator
}

ReadOptions controls JSON parsing. A nil *ReadOptions uses the defaults.

Jump to

Keyboard shortcuts

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