JsonFormatter
API reference › Foxy › Json › JsonFormatter
Formats JSON while retaining selected empty containers as arrays.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
format() static | Format the data in JSON. | JsonFormatter |
getArrayKeys() static | Get the list of keys to be retained with an array representation if they are empty. | JsonFormatter |
getMapKeys() static | Get the keys that were represented as empty JSON objects. | JsonFormatter |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
ARRAY_KEYS_REGEX | '/["\ | JsonFormatter | |
DEFAULT_INDENT | 4 | JsonFormatter | |
MAP_KEYS_REGEX | '/["\ | JsonFormatter |
Method details
Section titled “Method details”format()
Section titled “format() ”public static function format(string $json, string[] $arrayKeys = [], int $indent = \self::DEFAULT_INDENT, bool $formatJson = true): stringFormat the data in JSON.
Parameters
| Parameter | Type | Description |
|---|---|---|
$json | string | The original JSON. |
$arrayKeys | string[] | The list of keys to be retained with an array representation if they are empty. |
$indent | int | The space count for indent. |
$formatJson | bool | Check if the JSON must be formatted. |
Returns
string
Throws
JsonException: if the JSON cannot be decoded or encoded.
getArrayKeys()
Section titled “getArrayKeys() ”public static function getArrayKeys(string $content): arrayGet the list of keys to be retained with an array representation if they are empty.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | The content. |
Returns
array
getMapKeys()
Section titled “getMapKeys() ”public static function getMapKeys(string $content): arrayGet the keys that were represented as empty JSON objects.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string |
Returns
array