Skip to content
PHP Ecosystem
Explore

JsonFile

API reference › Foxy › Json › JsonFile

final classFoxy\Json\JsonFile
ExtendsComposer\Json\JsonFile
Sourcesrc/Json/JsonFile.php

Preserves empty arrays and objects while reading and writing package manifests.

MethodDescriptionDefined by
encode() staticEncode 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
public static function encode(mixed $data, int $options = \self::DEFAULT_OPTIONS, string $indent = \self::INDENT_DEFAULT): string

Encode 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

ParameterTypeDescription
$datamixed
$optionsint
$indentstring

Returns

string

public function getArrayKeys(): array

Get the list of keys to be retained with an array representation if they are empty.

Returns

array

public function read(): array

Reads the JSON document and records how its empty containers are represented.

Returns

array

public function write(array $hash, int $options = \self::DEFAULT_OPTIONS): void

Writes package data while preserving empty-array keys from the original document.

Parameters

ParameterTypeDescription
$hasharray
$optionsint