The Nuxed Json component provides functions that help you encode, and decode json structures safely.
This package can be installed with Composer.
$ composer require nuxed/json
use namespace Nuxed\Json;
use namespace Facebook\TypeSpec;
<<__EntryPoint>>
async function main(): Awaitable<void> {
$data = Json\encode(dict[
'foo' => 5,
'bar' => 6
]);
// using reified generics.
$decoded = Json\typed<dict<string, int>>($data);
// using type spec.
$decoded = Json\spec($data, TypeSpec\dict(
TypeSpec\string(), TypeSpec\int();
));
}
For information on reporting security vulnerabilities in Nuxed, see SECURITY.md.
Nuxed is open-sourced software licensed under the MIT-licensed.