0

I have JSON array object but I don't know how to get data from it. I have searched using Iterables & Iterators but I don't understand the concept.

{ '-LIDMHr69GLnq1Pyzt6o': 
       { author_avatar: 
          { image: 'https://lh3.googleusercontent.com/-jWM4ghUG930/AAAAAAAAAAI/AAAAAAAAAAo/q3nLLgvfOAs/photo.jpg',
            initials: 'UH',
            selection: 'image' 
          },
         author_name: 'AB',
         image: '/assets/images/icons/23.png',
         last_modified: 1542827537242,
         owner_id: 'HauqBY5dDtP0RFhrF1DvEDuFv812',
         team_id: 'private',
         title: 'this is test1'
      },         
      '-LJU_KEYGDv7hRHQ2ABo': 
       { author_avatar: 
          { image: 'https://lh3.googleusercontent.com/-jWM4ghUG930/AAAAAAAAAAI/AAAAAAAAAAo/q3nLLgvfOAs/photo.jpg',
            initials: 'UH',
            selection: 'image' 
          },
         author_name: 'AB',
         image: '/assets/images/icons/23.png',
         last_modified: 1542827549341,
         owner_id: 'HauqBY5dDtP0RFhrF1DvEDuFv812',
         team_id: 'private',
         title: 'this is test2' 
        } 
      }
Krishna Prashatt
  • 631
  • 9
  • 18

2 Answers2

0

I am unable to understand what is your desired output that well, but if you want to get the values of the JSON (and not knowing the keys) you can use one of the following:

Object.values(yourJson));

Object.keys(yourJson).map(key =>x[key]);

You can also check this one:

Object.entries(yourJson)
Alex
  • 166
  • 8
0

that code is not in a correct JSON string format. if change to

   ' {
  "-LIDMHr69GLnq1Pyzt6o": {
    "author_avatar": {
      "image": "https://lh3.googleusercontent.com/-jWM4ghUG930/AAAAAAAAAAI/AAAAAAAAAAo/q3nLLgvfOAs/photo.jpg",
      "initials": "UH",
      "selection": "image"
    },
    "author_name": "AB",
    "image": "/assets/images/icons/23.png",
    "last_modified": 1542827537242,
    "owner_id": "HauqBY5dDtP0RFhrF1DvEDuFv812",
    "team_id": "private",
    "title": "this is test1"
  },
  "-LJU_KEYGDv7hRHQ2ABo": {
    "author_avatar": {
      "image": "https://lh3.googleusercontent.com/-jWM4ghUG930/AAAAAAAAAAI/AAAAAAAAAAo/q3nLLgvfOAs/photo.jpg",
      "initials": "UH",
      "selection": "image"
    },
    "author_name": "AB",
    "image": "/assets/images/icons/23.png",
    "last_modified": 1542827549341,
    "owner_id": "HauqBY5dDtP0RFhrF1DvEDuFv812",
    "team_id": "private",
    "title": "this is test2"
  }
}'

you can use JSON.parse method to make it Object

const data = '{
  "-LIDMHr69GLnq1Pyzt6o": {
    "author_avatar": {
      "image": "https://lh3.googleusercontent.com/-jWM4ghUG930/AAAAAAAAAAI/AAAAAAAAAAo/q3nLLgvfOAs/photo.jpg",
      "initials": "UH",
      "selection": "image"
    },
    "author_name": "AB",
    "image": "/assets/images/icons/23.png",
    "last_modified": 1542827537242,
    "owner_id": "HauqBY5dDtP0RFhrF1DvEDuFv812",
    "team_id": "private",
    "title": "this is test1"
  },
  "-LJU_KEYGDv7hRHQ2ABo": {
    "author_avatar": {
      "image": "https://lh3.googleusercontent.com/-jWM4ghUG930/AAAAAAAAAAI/AAAAAAAAAAo/q3nLLgvfOAs/photo.jpg",
      "initials": "UH",
      "selection": "image"
    },
    "author_name": "AB",
    "image": "/assets/images/icons/23.png",
    "last_modified": 1542827549341,
    "owner_id": "HauqBY5dDtP0RFhrF1DvEDuFv812",
    "team_id": "private",
    "title": "this is test2"
  }
}';

const parse_data = JSON.parse(data);
console.log(parse_data);
Coding
  • 52
  • 5
  • This ... I wish JSON was originally named as TDIF, that would've reduced the missuse of the term radically. OP doesn't have JSON, they have a JS object. – Teemu Apr 12 '19 at 07:06