Nested JSON data is read one level at a time.

nested field Select the nested scalar that matters for the current decision.

Nested JSON

status
nested_json.php
Replay: real traced execution (multi-file project)
<?php
$status = "active";
$json = '{"user":{"name":"Ada","status":"' . $status . '"}}';
$userStatus = json_decode($json, true)["user"]["status"];
$enabled = $userStatus === "active" ? "yes" : "no";

echo "status=" . $status . "\n";
echo "enabled=" . $enabled . "\n";
<?php
$status = "paused";
$json = '{"user":{"name":"Ada","status":"' . $status . '"}}';
$userStatus = json_decode($json, true)["user"]["status"];
$enabled = $userStatus === "active" ? "yes" : "no";

echo "status=" . $status . "\n";
echo "enabled=" . $enabled . "\n";
<?php
$status = "archived";
$json = '{"user":{"name":"Ada","status":"' . $status . '"}}';
$userStatus = json_decode($json, true)["user"]["status"];
$enabled = $userStatus === "active" ? "yes" : "no";

echo "status=" . $status . "\n";
echo "enabled=" . $enabled . "\n";
  1. $status ← active, $json ← {"user":{"name":"Ada","status":"active"}}

    1<?php2$status→ active = "active"; //@status="paused", "archived"3$json→ {"user":{"name":"Ada","status":"active"}} = '{"user":{"name":"Ada","status":"' . $statusactive . '"}}';4$userStatus→ active = json_decode($json, true)["user"]["status"]active;5$enabled→ yes = $userStatusactive === "active" ? "yes" : "no";67echo "status=" . $statusactive . "\n";8echo "enabled=" . $enabledyes . "\n";
    outputstatus=active
    enabled=yes
  1. $status ← paused, $json ← {"user":{"name":"Ada","status":"paused"}}

    1<?php2$status→ paused = "paused";3$json→ {"user":{"name":"Ada","status":"paused"}} = '{"user":{"name":"Ada","status":"' . $statuspaused . '"}}';4$userStatus→ paused = json_decode($json, true)["user"]["status"]paused;5$enabled→ no = $userStatuspaused === "active" ? "yes" : "no";67echo "status=" . $statuspaused . "\n";8echo "enabled=" . $enabledno . "\n";
    outputstatus=paused
    enabled=no
  1. $status ← archived, $json ← {"user":{"name":"Ada","status":"archived"}}

    1<?php2$status→ archived = "archived";3$json→ {"user":{"name":"Ada","status":"archived"}} = '{"user":{"name":"Ada","status":"' . $statusarchived . '"}}';4$userStatus→ archived = json_decode($json, true)["user"]["status"]archived;5$enabled→ no = $userStatusarchived === "active" ? "yes" : "no";67echo "status=" . $statusarchived . "\n";8echo "enabled=" . $enabledno . "\n";
    outputstatus=archived
    enabled=no