Contents

JSONLoader

A loader backed by a JSON or JSONL file.

Declaration

struct JSONLoader<Sample> where Sample : SampleProtocol

Overview

let url = Bundle.main.url(forResource: "samples", withExtension: "jsonl")!
let loader = JSONLoader<ModelSample<String>>(url: url)

The format is detected automatically from the file contents:

  • If the first non-whitespace character is [, the file is treated as a JSON array ([{...}, {...}]) and decoded in one pass.

  • Otherwise, the file is treated as JSONL (JSON Lines), where the loader decodes each non-empty line as an individual sample.

Malformed entries are logged using OSLog and skipped. A failure to open the file propagates as a thrown error.

Topics

Initializers

Instance Properties

See Also

Loaders