Constants
Output modes
Every data-returning method accepts an optional $output argument.
| Constant | Value | Returns |
|---|---|---|
JsonFast::OUTPUT_ARRAY | 0 | PHP array (default) |
JsonFast::OUTPUT_STRING | 1 | JSON string |
JsonFast::OUTPUT_OBJECT | 2 | stdClass for JSON objects |
php
$data = JsonFast::minify($json); // array
$string = JsonFast::minify($json, JsonFast::OUTPUT_STRING); // string
$object = JsonFast::minify($json, JsonFast::OUTPUT_OBJECT); // stdClassTIP
OUTPUT_OBJECT only affects JSON objects. JSON arrays are always returned as PHP arrays.
Repair flags
Pass to repair() as a bitmask. Combine with bitwise OR (|).
| Constant | Description |
|---|---|
REPAIR_BOM | Strip UTF-8 byte order mark |
REPAIR_JSONP | Strip JSONP wrapper (callback(...)) |
REPAIR_COMMENTS | Remove // and /* */ comments |
REPAIR_TRAILING_COMMAS | Remove trailing commas |
REPAIR_DOUBLE_ENCODED | Unwrap double-encoded JSON strings |
REPAIR_UNQUOTED_STRINGS | Quote unquoted string values |
REPAIR_SINGLE_QUOTES | Convert single quotes to double quotes |
REPAIR_UNQUOTED_KEYS | Quote unquoted object keys |
REPAIR_ALL | All repair flags combined |
php
$flags = JsonFast::REPAIR_COMMENTS | JsonFast::REPAIR_TRAILING_COMMAS;
$fixed = JsonFast::repair($broken, $flags);analyse() returns suggested flags with their bit values so you can build a targeted mask instead of using REPAIR_ALL.
