Accessing nested JSON element in Javascript without using eval
<p>I have JSON below that I am trying to access.  </p>

<pre><code>{    
 "orders": {
   "errorData": {
     "errors": {
       "error": [
         {
           "code": "ERROR_01",
           "description": "API service is down"
         }
       ]
     }
   },
   "status": "fail"
 }
}
</code></pre>

<p>I want to be able to declare constants to refer to the JSON since the structure could change and I don't want to be re-factoring accesses all over the place. Say, I want to access the "status" key and use my constant.  Data refers to the JSON object.  I could try (This is in TypeScript):</p>

<pre><code>public static STATUS : string = "data["orders"]["status"]";
var status_value = STATUS;
</code></pre>

<p>The problem is that this is simply assigning the string STATUS to the variable "status_value", not actually evaluating it.  I could call eval on STATUS, but I want to avoid that.  I know there is a loop answer, but it seems a tad over-kill since I'll be accessing this all over the code. (It's an Angular 2 app so lots of back-end calls and parsing JSON) </p>

<p>I could write the loop function as a constant and call it?  Any advice would be great, as I am new to Javascript. </p>