title: Codeigniter json_decode view as a variable returns NULL
body: <p>Can't seem to find the solution to this, I want to load json data from a view variable like this</p>
  
  <pre><code> $this-&gt;json = $this-&gt;load-&gt;view('/jsonfiles/page.json','',true);
  </code></pre>
  
  <p>Outputting</p>
  
  <pre><code>var_dump(json_decode($this-&gt;json,true));
  </code></pre>
  
  <p><strong>= NULL</strong> </p>
  
  <p>The View seems to be rendering the .json file incorrectly, for the json_decode to fail. (maybe not incorrectly, but in a different format), Ive already tried to utf8_encode, no luck</p>
  
  <p>JSON Variable within the page.json</p>
  
  <pre><code>[
    {
      "page" : {
        "name" : "PageNameHere",
        "date" : true
      }
    }
  ]
  </code></pre>
  
  <p>Or is there an alternative to doing this? </p>
  
  <p><strong>UPDATE</strong>: Yes it works when its an actual string in the variable like this </p>
  
  <pre><code>$this-&gt;json = '[{"page":{"name":"PageNameHere","date":true}}]';
  var_dump(json_decode($this-&gt;json,true));
  </code></pre>
  
  <p><strong>SOLUTION</strong>: So I've decided to figure this out one, and by my mistake, I had a "," comma in the last part of my JSON, which wasn't in this thread, I shorten the JSON for topic, but I found it, using this neat error switch, able to find JSON rendering errors</p>
  
  <pre><code> switch (json_last_error()) {
      case JSON_ERROR_NONE:
          echo ' - No errors';
      break;
      case JSON_ERROR_DEPTH:
          echo ' - Maximum stack depth exceeded';
      break;
      case JSON_ERROR_STATE_MISMATCH:
          echo ' - Underflow or the modes mismatch';
      break;
      case JSON_ERROR_CTRL_CHAR:
          echo ' - Unexpected control character found';
      break;
      case JSON_ERROR_SYNTAX:
          echo ' - Syntax error, malformed JSON';
      break;
      case JSON_ERROR_UTF8:
          echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
      break;
      default:
          echo ' - Unknown error';
      break;
  }
  </code></pre>
  
  <p>My Issue was labeled as "<strong>Syntax error, malformed JSON</strong>" </p>