NEON Functions

NEON is a human-friendly data serialization language. It is used in Nette for configuration files. Nette\Neon\Neon is a static class for working with NEON.

Try it on the sandbox.


composer require nette/neon

The following examples use these aliases:

use Nette\Neon\Neon;

encode(mixed $value, int $flags=0)string

Returns $value converted to NEON. The flag can be Neon::BLOCK, which will create multiline output.

Neon::encode($value); // Returns $value converted to NEON
Neon::encode($value, Neon::BLOCK); // Returns $value converted to multiline NEON

Method encode() throws Nette\Neon\Exception on error.

try {
	$neon = Neon::encode($value);
} catch (Nette\Neon\Exception $e) {
	// Exception handling

decode(string $neon): mixed

Converts given NEON to PHP value.

Returns scalars, arrays, DateTimeImmutable and Nette\Neon\Entity objects.

Neon::decode('hello: world'); // Returns an array ['hello' => 'world']

Method decode() throws Nette\Neon\Exception on error.

try {
	$value = Neon::decode($neon);
} catch (Nette\Neon\Exception $e) {
	// Exception handling
version: 3.4 2.x