JsonFile
API reference › Foxy › Json › JsonFile
Preserves empty arrays and objects while reading and writing package manifests.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
encode() static | Encode package manifest data as JSON. | JsonFile |
getArrayKeys() | Get the list of keys to be retained with an array representation if they are empty. | JsonFile |
read() | Reads the JSON document and records how its empty containers are represented. | JsonFile |
write() | Writes package data while preserving empty-array keys from the original document. | JsonFile |
Method details
Section titled “Method details”encode()
Section titled “encode() ”public static function encode(mixed $data, int $options = \self::DEFAULT_OPTIONS, string $indent = \self::INDENT_DEFAULT): stringEncode package manifest data as JSON.
Empty root arrays are encoded as objects because package manifests must have an object root.
The $indent argument is retained for Composer compatibility; Foxy always uses four spaces.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | mixed | |
$options | int | |
$indent | string |
Returns
string
getArrayKeys()
Section titled “getArrayKeys() ”public function getArrayKeys(): arrayGet the list of keys to be retained with an array representation if they are empty.
Returns
array
read()
Section titled “read() ”public function read(): arrayReads the JSON document and records how its empty containers are represented.
Returns
array
write()
Section titled “write() ”public function write(array $hash, int $options = \self::DEFAULT_OPTIONS): voidWrites package data while preserving empty-array keys from the original document.
Parameters
| Parameter | Type | Description |
|---|---|---|
$hash | array | |
$options | int |