Skip to content

minify()

Parse JSON and return a compact representation or PHP value.

Signature

php
JsonFast::minify(string $json, ?int $output = OUTPUT_ARRAY): mixed

Parameters

NameTypeDefaultDescription
$jsonstringValid JSON text
$output?intOUTPUT_ARRAYOutput mode

Returns

ModeResult
OUTPUT_ARRAYNative PHP array (default) — fastest path to working with data
OUTPUT_STRINGMinified JSON string (no extra whitespace)
OUTPUT_OBJECTstdClass 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 $output across all JsonFast methods
  • Same Rust parser used for path, schema, and diff operations
  • Order-preserving object keys (serde_json)

Native tools, weird experiments, and practical performance work.