<!--
{
  "availability" : [
    "Xcode: 27.0.0 -",
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Evaluations",
  "identifier" : "/documentation/Evaluations/JSONLoader",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Evaluations"
    ],
    "preciseIdentifier" : "s:11Evaluations10JSONLoaderV"
  },
  "title" : "JSONLoader"
}
-->

# JSONLoader

A loader backed by a JSON or JSONL file.

```
struct JSONLoader<Sample> where Sample : SampleProtocol
```

## Overview

```swift
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

[`init(url: URL)`](/documentation/Evaluations/JSONLoader/init(url:))

Creates a loader backed by the JSON or JSONL file at the given URL.

### Instance Properties

[`var stream: any AsyncSequence<Sample, any Error>`](/documentation/Evaluations/JSONLoader/stream)

The async sequence that reads and yields each sample from the JSON or JSONL file during an evaluation run.

## Relationships

### Conforms To

[`Loader`](/documentation/Evaluations/Loader)

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)