NDJSON and Structured JSON Workflows
Design stable streaming schemas, handle extra keys, and bridge spreadsheet sessions to structured JSON responses.
Updated
toStructuredJson()saveStructuredJson()json_columnsstreaming_extra_keysWhat you will learn
- Define a deterministic column order for streamed records.
- Choose whether unknown record keys are ignored or rejected.
- Convert any compatible read session into workbook-aware JSON.
Pin a streaming schema#
$rows = Json::read('audit.ndjson', [
'json_document_mode' => 'ndjson',
'json_columns' => ['event_id', 'actor', 'action', 'occurred_at'],
'include_header_row' => true,
'streaming_extra_keys' => 'error',
])->withHeaderRow(1)->rows();Convert XLSX to a structured JSON response#
$json = MnbExcel::read('report.xlsx')
->withHeaderRow(1)
->toStructuredJson(
readOptions: ['preserve_original_row_numbers' => true],
jsonOptions: ['pretty' => true]
);
header('Content-Type: application/json; charset=UTF-8');
echo $json;Apply defensive limits#
- Set
max_file_bytesbefore parsing uploads. - Set
max_json_record_bytesfor NDJSON and streamed arrays. - Use
max_source_rowsand row slicing for bounded work. - Use
depthto cap JSON nesting accepted by the decoder.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue