Skip to content

Constants

Output modes

Every data-returning method accepts an optional $output argument.

ConstantValueReturns
JsonFast::OUTPUT_ARRAY0PHP array (default)
JsonFast::OUTPUT_STRING1JSON string
JsonFast::OUTPUT_OBJECT2stdClass for JSON objects
php
$data   = JsonFast::minify($json);                           // array
$string = JsonFast::minify($json, JsonFast::OUTPUT_STRING); // string
$object = JsonFast::minify($json, JsonFast::OUTPUT_OBJECT);  // stdClass

TIP

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 (|).

ConstantDescription
REPAIR_BOMStrip UTF-8 byte order mark
REPAIR_JSONPStrip JSONP wrapper (callback(...))
REPAIR_COMMENTSRemove // and /* */ comments
REPAIR_TRAILING_COMMASRemove trailing commas
REPAIR_DOUBLE_ENCODEDUnwrap double-encoded JSON strings
REPAIR_UNQUOTED_STRINGSQuote unquoted string values
REPAIR_SINGLE_QUOTESConvert single quotes to double quotes
REPAIR_UNQUOTED_KEYSQuote unquoted object keys
REPAIR_ALLAll 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.

Native tools, weird experiments, and practical performance work.