title: Axios - How to read JSON response?
body: <p>Axios 0.17.1</p>
  
  <pre><code>.then(function (response) {
                  console.log(response);
                  //console.log(response.status);
                  //It is an error -&gt; SyntaxError: Unexpected token u in JSON at position 0 
                  console.log(JSON.parse(response.data.error));
                  console.log(response.data.error); //undefined.
  </code></pre>
  
  <p>The console.log of response is</p>
  
  <blockquote>
    <p>{data: "{"error":"Name must be entered with more than one …  NULL↵<br>
    ["isPipe":protected]=>↵    NULL↵  }↵}↵", status: 203, statusText:
    "Non-Authoritative Information", headers: {…}, config: {…}, …} config
    : {adapter: ƒ, transformRequest: {…}, transformResponse: {…}, timeout:
    0, xsrfCookieName: "XSRF-TOKEN", …} data : "{"error":"Name must be
    entered with more than one character."}object(Slim\Http\Response)#32
    (5) {↵  ["status":protected]=>↵  int(200)↵ 
    ["reasonPhrase":protected]=>↵  string(0) ""↵ 
    ["protocolVersion":protected]=>↵  string(3) "1.1"↵ 
    ["headers":protected]=>↵  object(Slim\Http\Headers)#33 (1) {↵<br>
    ["data":protected]=>↵    array(1) {↵      ["content-type"]=>↵<br>
    array(2) {↵        ["value"]=>↵        array(1) {↵          [0]=>↵<br>
    string(24) "text/html; charset=UTF-8"↵        }↵<br>
    ["originalKey"]=>↵        string(12) "Content-Type"↵      }↵    }↵  }↵
    ["body":protected]=>↵  object(Slim\Http\Body)#31 (7) {↵<br>
    ["stream":protected]=>↵    resource(59) of type (stream)↵<br>
    ["meta":protected]=>↵    NULL↵    ["readable":protected]=>↵    NULL↵<br>
    ["writable":protected]=>↵    NULL↵    ["seekable":protected]=>↵<br>
    NULL↵    ["size":protected]=>↵    NULL↵    ["isPipe":protected]=>↵<br>
    NULL↵  }↵}↵" headers : {content-type:
    "application/json;charset=utf-8"} request : XMLHttpRequest
    {onreadystatechange: ƒ, readyState: 4, timeout: 0, withCredentials:
    false, upload: XMLHttpRequestUpload, …} status : 203 statusText :
    "Non-Authoritative Information"
    <strong>proto</strong> : Object</p>
  </blockquote>
  
  <p>JSON.parse(response.data) as well as response.data.error -> Both are giving error. How can i read the data?</p>
  
  <p>Slimframework 3. </p>
  
  <pre><code>$data = array('error' =&gt; 'Name must be entered with more than one character.');
          $newResponse = $response-&gt;withJson($data, 203);
          return $newResponse;
  </code></pre>