codedancer
codedancer

Reputation: 1634

GraphQL json output to pandas dataframe

I tried a few ways to convert a json output from GraphQL to a pandas dataframe but I was not able to get it right. What's the best way to convert it into a pandas dataframe?

{'data': {'posts': {'edges': [{'node': {'id': '303843',
      'name': 'hipCV',
      'tagline': 'Create an impressive resume in minutes',
      'votesCount': 71}},
    {'node': {'id': '303751',
      'name': 'Find Your First Frontend Job',
      'tagline': "Find your dream job, even if you've been rejected many times",
      'votesCount': 51}},
    {'node': {'id': '303665',
      'name': 'Epsilon3',
      'tagline': 'The OS for spacecraft and complex operations',
      'votesCount': 290}}]}}}

Upvotes: 1

Views: 3038

Answers (1)

Anurag Dabas
Anurag Dabas

Reputation: 24314

Try:

df=pd.json_normalize(data['data']['posts']['edges'])
#here data is your json data
#If needed use:
df.columns=df.columns.str.split('.').str[1]

output of df:

   node.id  node.name                       node.tagline                                    node.votesCount
0   303843  hipCV                           Create an impressive resume in minutes              71
1   303751  Find Your First Frontend Job    Find your dream job, even if you've been rejec...   51
2   303665  Epsilon3                        The OS for spacecraft and complex operations        290

Upvotes: 3

Related Questions