0

I'm given some JSON object from a site I need to pull some information from. It's giving to to me in a form like:

{   "status": true,   
"number_of_things": 2,   
"things": {
    "SOMETHING I DONT KNOW 1": {
      "meta": {
        "description": "DESCRIPTION OF THING1"
      },
      "status": {
          "in_current_state_since": "2021-09-14T00:11:09Z",
        "minutes_in_current_state": 8798
      }
    },
    "SOMETHING I DONT KNOW 2": {
      "meta": {
        "description": "DESCRIPTION OF THING2"
      },
      "status": {
          "in_current_state_since": "2021-09-14T00:11:09Z",
        "minutes_in_current_state": 8798
      }
    }   } }

I want to try and get the description field but I don't know or care about the "something i don't know" keys. is there a way to index it like
myParsedJSON.things[index].meta.description ?

I basically want to index through all of the "things" and print out the description of each. so look "number of things" times.

Moses
  • 1
  • 1
  • you can get list of key-value pairs with `Object.entries` - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries – Ruslan Tushov Sep 20 '21 at 05:07
  • Note that you can’t rely on the order of keys. The next API call, the order may be completely different. Familiarize yourself with [how to access and process nested objects, arrays or JSON](/q/11922383/4642212) and use the available static and instance methods of [`Object`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object#Static_methods) and [`Array`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array#Static_methods). – Sebastian Simon Sep 20 '21 at 05:09
  • Thanks, Object.entries did it for me! – Moses Sep 20 '21 at 12:29

0 Answers0