minify()
Parse JSON and return a compact representation or PHP value.
Signature
php
JsonFast::minify(string $json, ?int $output = OUTPUT_ARRAY): mixedParameters
| Name | Type | Default | Description |
|---|---|---|---|
$json | string | — | Valid JSON text |
$output | ?int | OUTPUT_ARRAY | Output mode |
Returns
| Mode | Result |
|---|---|
OUTPUT_ARRAY | Native PHP array (default) — fastest path to working with data |
OUTPUT_STRING | Minified JSON string (no extra whitespace) |
OUTPUT_OBJECT | stdClass for objects; arrays stay as PHP arrays |
Examples
Default — decode to array:
php
$json = '{"name":"Allan","active":true,"roles":["admin","user"]}';
$data = JsonFast::minify($json);
// ['name' => 'Allan', 'active' => true, 'roles' => [...]]Compact string for storage or wire:
php
$compact = JsonFast::minify($json, JsonFast::OUTPUT_STRING);Object access:
php
$object = JsonFast::minify($json, JsonFast::OUTPUT_OBJECT);
echo $object->name;vs json_decode()
minify() requires valid JSON. For invalid input use repair() first. Benefits over json_decode() alone:
- Consistent
$outputacross all JsonFast methods - Same Rust parser used for path, schema, and diff operations
- Order-preserving object keys (
serde_json)
Related
beautify()— pretty-printvalidate()— check before parsing
