Reading JSON and NDJSON
Stream top-level arrays and line-delimited records, select workbook sheets, and control normalized columns.
Updated
Json::read()sheetNames()streaming()projectColumns()What you will learn
- Stream standard arrays or NDJSON without loading the entire source.
- Define stable columns for heterogeneous records.
- Select named sheets from workbook-shaped JSON.
Stream a top-level array#
$rows = Json::read('events.json', [
'stream_json_array' => true,
'json_columns' => ['id', 'type', 'created_at'],
'streaming_extra_keys' => 'error',
'max_json_record_bytes' => 2 * 1024 * 1024,
])->withHeaderRow(1)->streaming()->rows();Read NDJSON explicitly#
$rows = Json::read('events.ndjson', [
'json_document_mode' => 'ndjson',
'ignore_blank_lines' => true,
'max_source_rows' => 1000000,
])->withHeaderRow(1)->rows();Select a sheet from workbook-shaped JSON#
$session = Json::read('workbook.json', [
'json_document_mode' => 'json',
]);
print_r($session->sheetNames());
$orders = $session->sheet('Orders')->withHeaderRow(1)->rows();Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue