use yii\helpers\Json; $data = '{"name":"John","age":30,"city":"New York"}'; $decodedData = Json::decode($data); echo $decodedData['name']; // Output: John echo $decodedData['age']; // Output: 30 echo $decodedData['city']; // Output: New York
use yii\helpers\Json; $data = [ 'name' => 'John', 'age' => 30, 'city' => 'New York' ]; $encodedData = Json::encode($data); echo $encodedData; // Output: {"name":"John","age":30,"city":"New York"}The `Json` helper is part of the `yii\helpers` package library in Yii.