MNB PHPExcelDeveloper Guide

JSON · Structured output

JSON structured output examples.

Package-local, copy-ready examples organized like the classes and methods reference. Open one example at a time, search by method, and jump from the right-side index.

Packagemnb/mnb-phpexcel-json:^2.0Reference1 examples · 2 methods
JSON individual library

Structured output examples with copy-ready, production-minded PHP.

Every snippet uses mnb/mnb-phpexcel-json or its declared Core dependency. Each copied snippet includes strict typing, a concise summary, implementation guidance, readable limits, and a safe fixture check.

1
examples
2
documented methods
Example 01

Return a structured JSON response

Open related guide
toStructuredJson()saveStructuredJson()
return-a-structured-json-response.php
<?php

declare(strict_types=1);

/*
Summary:
    Return workbook-aware rows, counts, warnings, and source metadata as an API response.

Implementation note:
    Structured output preserves the reader summary and warnings instead of returning only a flat
    list of rows.
*/

use Mnb\PHPExcel\Format\Json;

$json = Json::read(__DIR__ . '/report.json')
    ->withHeaderRow(1)
    ->toStructuredJson(
        readOptions: ['preserve_original_row_numbers' => true],
        jsonOptions: ['pretty' => true]
    );

header('Content-Type: application/json; charset=UTF-8');
echo $json;