JSON Encode and Decode in PHP
Round-trip JSON with JSON_THROW_ON_ERROR for safe decoding.
Author:
chris
// Language: PHP
<?php
declare(strict_types=1);
$raw = '{"name":"chris","tags":["php","laravel"]}';
$data = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
$data['tags'][] = 'symfony';
echo json_encode($data, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR), PHP_EOL;