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 ¶
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 ¶
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.
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.