Passing JSON from controller to view in codeigniter
<p>I made an API call and received the response in JSON format.</p>

<p>JSON:
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>{
  "Specialities": [
    {
      "SpecialityID": 1,
      "SpecialityName": "Eye Doctor"
    },
    {
      "SpecialityID": 2,
      "SpecialityName": "Chiropractor"
    },
    {
      "SpecialityID": 3,
      "SpecialityName": "Primary Care Doctor"
    }
  ]
}</code></pre>
</div>
</div>
</p>

<p>Controller File:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>public function index(){
      $data= json_decode(file_get_contents('some_url'));
      $this-&gt;load-&gt;view('my_view',$data);
}</code></pre>
</div>
</div>
</p>

<p>Above code doesn't work because in view I can't access the nested object properties. However I am able to echo the JSON properties in controller file just like this:</p>

<p>Controller File:
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>public function index(){

     $data=json_decode(file_get_contents('some_url'));
     foreach ($data as $key=&gt;$prop_name){
        for($i=0;$i &lt; count($prop_name);$i++){
          echo $prop_name[$i]-&gt;SpecialityID;
          echo $prop_name[$i]-&gt;SpecialityName;
        }
     }
}</code></pre>
</div>
</div>
</p>

<p>My question is how do I pass this JSON to view and how can I access those properties in view file?</p>