[PHP] Decode a JSON object with json_decode()

Created on November 30, 2026

You can pass a JSON string to json_decode() to work with it in PHP. By default, a JSON object becomes a PHP object, and its fields are available as properties.

<?php

$json = <<< JSON
{
  "name": "tanaka",
  "age": 20
}
JSON;

$jsonObject = json_decode($json);
echo $jsonObject->name . ': ' . $jsonObject->age;

The example reads name and age from the decoded object.

tanaka: 20
PHP