Skip to main content

Module phpjson

Module phpjson 

Source
Expand description

JSON re-encoding reproducing PHP’s json_encode($data, 0) applied to data coming from json_decode($json, true) (the JsonFile::parseJson -> JsonFile::encode pipeline, Composer 2.10.3, see docs/reference/JsonFile.php).

Byte-exact semantics:

  • compact output ({"k":v}), insertion order preserved;
  • / escaped as \/, non-ASCII as lowercase-hex \uXXXX (surrogate pairs beyond the BMP), controls \b \f \n \r \t then \u00XX;
  • assoc quirk: an empty object becomes [], an object whose keys are exactly “0”..“n-1” in order becomes an array (PHP lost the object/array distinction at decode time);
  • shortest round-trip floats (serialize_precision=-1): fixed notation without a trailing .0 for integral values (1.0 -> 1), exponential d[.ddd|.0]e±X outside (-4, 17]; see encode_double.

Structs§

EncodeOptions
Options mirroring the json_encode flags used by Composer.

Constants§

FLAGS_JSONFILE
JsonFile default (files written by Composer): JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE.
FLAGS_ZERO
Flags 0 (content-hash): compact, slashes and unicode escaped.
STDCLASS_MARKER
Sentinel key: an object reduced to this key encodes as {} (an empty stdClass on the PHP side, which the array semantics cannot express).

Functions§

empty_stdclass
An empty object that will encode as {}.
php_json_encode
php_json_encode_with