Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 2

Parsing GraphQL v4 Query results

Solved! Go to Solution.

Hi, I would like to parse my query result to infos mapped to the key so i can store in a csv file. Here is an exemple query I'm working with. 

{'node':{
    'owner': {'login': 'freeCodeCamp'},
    'name': 'freeCodeCamp',
    'stargazers': {'totalCount': 303161}, 'forkCount': 21994, 
    'defaultBranchRef': {
        'target': {
            'history': {
                'totalCount': 23177, 
                'edges': [{
                     'node': {
                          'committedDate': '2019-06-01T14:06:54Z'}
               }]}}}}}

My question is should I go with a parser fitting the the layout of my data or should i convert it to a string and use regex? And by any change does any one has a tool for easier parsing? I'm new to this and don't know where to start.

Cheers :)

1 Reply
Solution
Copilot Lvl 3
Message 2 of 2

Re: Parsing GraphQL v4 Query results

I found the answer which was straight forward. I'm just accessing the diferrent values by there key with something lookinh like this ( i being the index of the list)

data['data']['search']['edges'][i]['node']['owner']['login'],
data['data']['search']['edges'][i]['node']['name'],
data['data']['search']['edges'][i]['node']['stargazers']['totalCount'],
data['data']['search']['edges'][i]['node']['forkCount'],
data['data']['search']['edges'][i]['node']['defaultBranchRef']['target']['history']['totalCount']