Convert JSON from graphql API to array

Asked

Viewed 66 times

-1

I have a research connection to a API graphql, this search returns a JSON, where I store it in content and then turn it into an array, but this array is not showing the values contained in it, keeps the values in [array], instead of showing via console.log()

Script

require('es6-promise').polyfill();
require('isomorphic-fetch');

let queryAPI = {

    "query": `{
                squads {
                    name
                        cards(includedOnKanban: true, closed: false, archived: false, cancelled: false, updatedSince: \"2020-01-01T00:00:00-0300\") {
                            identifier
                            title
                            description
                            status
                            priority

                            assignees {
                                fullname
                                email
                              }

                        }
                    }
            }`

};

(async () => {
  const rawResponse = await fetch('https://www.bluesight.io/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Bluesight-API-Token': 'token-here'
    },
    body: JSON.stringify(queryAPI)
  });
  const content = await rawResponse.json();

  //console.log(JSON.stringify(content.data));

  var result = [];

  for(var i in content)
      result.push([i, content[i]]);
      console.log(content[i])

})();

JSON String example:

{ "date": { "squads": [ { "name": "SUPPORT IT", "cards": [ { "Dentifier": "06x38y", "title": "ALL - Validate data, "Description": "review database.", "status": null, "Priority": "medium", "assignees": [ { "fullname": "Carlos", "email": "[email protected]", } ] } ] } ] } }

OUTPUT

{
  squads: [ { name: 'SUPPORT IT', cards: [Array] } ]
}

1 answer

1


The.log() console may not be very specific if you don’t have an array exactly, basically, do:

console.log(content[i]["squads"][0]["cards"]); //Index 0 como exemplo, você pode colocar um 2° for

And it will show on the screen the array with your data

  • 1

    opaaa, was msm my doubt, mt obg!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.