Nette Documentation Preview

syntax
NEON Functions
**************

<div class=perex>

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

[Try it on the sandbox |https://ne-on.org].

</div>

Installation:

```shell
composer require nette/neon
```

The following examples use these aliases:

```php
use Nette\Neon\Neon;
```


encode(mixed $value, int $flags=0): string .[method]
----------------------------------------------------

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

```php
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.

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


decode(string $neon): mixed .[method]
-------------------------------------

Converts given NEON to PHP value.

Returns scalars, arrays, DateTimeImmutable and [api:Nette\Neon\Entity] objects.

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

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

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


{{leftbar: utils:@left-menu}}

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.

Installation:

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
}