Edit
Version 2.4

NEON

NEON is a human friendly data serialization language. Try it on the sandbox.

It is similar to YAML. The main difference is that the NEON supports “entities” (so can be used e.g. to DI configuration) and tab characters for indentation. NEON syntax is a little simpler and the parsing is faster.

Encoding and decoding

Nette\Neon\Neon is a static class with useful functions you can use to work with NEON. It sanitizes errors in different PHP versions and throws exceptions on errors.

The following examples use these aliases:

use Nette\Neon\Neon;

encode($value, $flags = 0)

Returns $value encoded into NEON. Flags accepts Neon::BLOCK which formats NEON in multiline format.

Neon::encode($value); // Returns $value encoded in NEON
Neon::encode($value, Neon::BLOCK); // Returns formatted $value encoded in NEON

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

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

decode($neon)

Converts given NEON to PHP value.

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
}

See NEON for JavaScript and NEON for Python.

IDE integration

NetBeans IDE has built-in support, check out NEON plugin for PhpStorm and Visual Studio Code.

Syntax

NEON is superset of JSON. So every JSON can be parsed as NEON:

{
"php": {
    "date.timezone": "Europe\/Prague",
    "zlib.output_compression": true
},
"database": {
    "driver": "mysql",
    "username": "root",
    "password": "beruska92"
},
"users": [
    "Dave", "Kryten", "Rimmer"
]
}

What if we could omit quotes?

{
php: {
    date.timezone: Europe/Prague,
    zlib.output_compression: true
},
database: {
    driver: mysql,
    username: root,
    password: beruska92
},
users: [
    Dave, Kryten, Rimmer
]
}

How about braces and commas?

php:
    date.timezone: Europe/Prague
    zlib.output_compression: true

database:
    driver: mysql
    username: root
    password: beruska92

users: [
    Dave, Kryten, Rimmer
]

Are bullets more legible?

php:
    date.timezone: Europe/Prague
    zlib.output_compression: true

database:
    driver: mysql
    username: root
    password: beruska92

users:
    - Dave
    - Kryten
    - Rimmer

How about comments?

# my web application config

php:
    date.timezone: Europe/Prague
    zlib.output_compression: yes  # use gzip

database:
    driver: mysql
    username: root
    password: beruska92

users:
    - Dave
    - Kryten
    - Rimmer

You found NEON syntax!