title: Dynamically update a nested JSON ( unknown level) using php
body: <p>I would like to update a json file using PHP</p>
  <pre><code>$Folder = $_REQUEST['Folder']; // &quot;wwwroot/JSON/&quot;
  $File = $_REQUEST['File']; // &quot;JSONOriginalFile.json&quot;
  $NewJSONValue = $_REQUEST['JsonValue']; // &quot;NewValue&quot;
  $JsonObject = json_decode($_REQUEST['JsonObect']); // [&quot;Layer1&quot;,&quot;Layer2&quot;,&quot;ObjectToUpdate&quot;]
  $JSON = file_get_contents($Folder.$File);
  $JSON = json_decode($JSON);
  </code></pre>
  <p>The goal here is to run something dynamic that would do</p>
  <pre><code>$JSON-&gt;Layer1-&gt;Layer2-&gt;ObjectToUpdate = $NewJSONValue;
  $JSON= json_encode($JSON);
  file_put_contents('../../'.$Folder.'/'.$File, $JSON);
  </code></pre>
  <p>But i can't go in a dynamic nested layers ex: i could try with the same &quot;app&quot; to update [&quot;Layer1&quot;,&quot;ObjectToUpdate&quot;] or [&quot;Layer1&quot;,&quot;Layer2&quot;,&quot;Layer3&quot;,&quot;ObjectToUpdate&quot;] or simply [&quot;ObjectToUpdate&quot;] etc..</p>
  <p>the goal is to have the array being transposed as nested search and the last array object the object to update.</p>
  <p>is there something like this that exists within php?</p>
  <p>even if run something like</p>
  <pre><code>$JsonString = &quot;$JSON&quot;;
  foreach($JsonObject as $Object) {
     $JsonString .= &quot;-&gt;&quot;.$Object;
  }
  </code></pre>
  <p>it does not help. anyone has a solution?</p>