jsonsource

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJsonFileSource

func NewJsonFileSource(filePath string) *arraysource.Model

NewJsonFileSource reads a JSON or JSONL file and returns an array-backed data source ready for querying with the array driver.

The file must contain either:

  • A JSON array of objects: [{"id":1,"name":"Alice"},...]
  • JSONL/NDJSON (one object per line): {"id":1,"name":"Alice"}\n{"id":2,...}

JSONL mode is auto-detected from the file extension (.jsonl or .ndjson). For .json files, the content is parsed as a single JSON array.

JSON has native types, so no string-to-type inference is needed — values are already int, float64, bool, string, or nil. String values that match RFC3339 format are converted to time.Time so the array driver maps them to DATETIME columns. Nested objects and arrays are stored as JSON strings (queryable via SQLite JSON functions).

The table name is derived from the filename (without the extension). For example, "data/users.json" → table name "users". Override with the .Table() method on the returned model if needed.

database.Query().
    Model(neat.NewJsonFileSource("data/users.json")).
    Where("active = ?", true).
    Get(&users)

Panics if the file cannot be opened, parsed, or contains an empty array — there is no header row like CSV to infer column names from, so an empty JSON array cannot produce a queryable table. These are programmer errors (wrong path, malformed file), not runtime conditions.

func NewJsonSource

func NewJsonSource(jsonString string, tableName string, isJSONL bool) *arraysource.Model

NewJsonSource parses a JSON or JSONL string and returns an array-backed data source ready for querying with the array driver.

The content must be either:

  • A JSON array of objects: [{"id":1,"name":"Alice"},...]
  • JSONL/NDJSON (one object per line): {"id":1,"name":"Alice"}\n{"id":2,...}

Pass isJSONL=true for JSONL content, false for a JSON array. For JSONL, empty lines are skipped.

JSON has native types, so no string-to-type inference is needed — values are already int, float64, bool, string, or nil. String values that match RFC3339 format are converted to time.Time so the array driver maps them to DATETIME columns. Nested objects and arrays are stored as JSON strings (queryable via SQLite JSON functions).

The table name must be provided explicitly since there is no filename to derive it from. Override with the .Table() method on the returned model if needed.

database.Query().
    Model(neat.NewJsonSource(jsonString, "users", false)).
    Where("active = ?", true).
    Get(&users)

Panics if the content cannot be parsed — this is a programmer error (malformed JSON), not a runtime condition. Panics if the content cannot be parsed or is an empty array — there is no header row like CSV to infer column names from, so an empty JSON array cannot produce a queryable table. This is a programmer error, not a runtime condition.

Types

This section is empty.

Jump to

Keyboard shortcuts

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