To::JSON()

Encodes data to JSON string.

Table of Contents
  1. Description
  2. Example

Description

To::JSON(mixed $value, bool|int|string $dent = false): ?string;

This method encodes PHP data to JSON string so that it can be stored to a file.

Example

$value = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5];

save('.\lot\asset\data.json', To::JSON($value, true));
$value = To::JSON(['a' => 1, 'b' => [1, [2]], 'c' => []], true); // Dent with 4 space(s)
$value = To::JSON(['a' => 1, 'b' => [1, [2]], 'c' => []], 2); // Dent with 2 space(s)
$value = To::JSON(['a' => 1, 'b' => [1, [2]], 'c' => []], "\t"); // Dent with 1 tab

To::JSON()

Encodes data to JSON string.

To::URL()

Converts private file path to public URL, or decodes URL special characters.

To::entity()

Converts characters to their corresponding HTML entities.

To::file()

Converts current value to a safe file name.

To::path()

Converts public URL to private file path.