Feeding JSON and JSONL to an LLM
JSON is the one format where the right answer is sometimes "don't convert it" — models read JSON fluently, and nested structures can lose precision when flattened. The problems worth solving are different: orientation (what shape is this file?) and repetition (JSONL logs that spell every key on every line).
When to leave it alone
A small config or API payload the model must reason about field-by-field? Paste it as JSON. Convert when the file is big (the model needs a map, not a dump), tabular in disguise (JSONL where every line shares the same keys), or headed for a workspace (raw .json/.jsonl uploads are rejected by several platforms; Markdown never is).
The element mapping
| In the file | In the Markdown |
|---|---|
| Any JSON document | A structure outline — `orders` — array[1204] of object, path by path — so the model learns the shape in ~40 lines |
| The document body | A fenced JSON block, size-capped with an explicit truncation note |
| JSONL with uniform objects | A records table: union of keys as typed columns, first 50 rows, truncation stated |
| JSONL with mixed shapes | Outlined per shape instead of forced into one table |
| Corrupt lines in JSONL | Skipped and counted in a fidelity warning — logs are never clean |
| Byte-order marks, trailing junk | Stripped/tolerated so real-world exports parse |
Why the outline matters
Ask a model a question about a 2 MB JSON dump and it reads until its attention thins out. Give it a 40-line outline first and it knows where everything lives — then the capped body (or your follow-up paste of one subtree) fills in details. It's the table-of-contents trick, applied to data.
Before → after
In the file
{"ts":"2026-07-01T09:14:22Z","route":"/api/convert","status":200,"ms":41}
{"ts":"2026-07-01T09:14:25Z","route":"/api/convert","status":500,"ms":902}
not json at all — a stray log line
{"ts":"2026-07-01T09:14:29Z","route":"/api/health","status":200,"ms":3}In the Markdown
| ts (str) | route (str) | status (int) | ms (int) |
| --- | --- | --- | --- |
| 2026-07-01T09:14:22Z | /api/convert | 200 | 41 |
| 2026-07-01T09:14:25Z | /api/convert | 500 | 902 |
1 malformed line was skipped (counted in the report).FAQ
Is anything recomputed or reordered? No — keys and values pass through untouched; only presentation is added.
.ndjson? Same parser as .jsonl.
Really deep nesting? The outline caps its depth and says so; the fenced body keeps the truth.
Drop an API log and watch it become a typed records table with the bad lines counted.