Rer e
Rer e

Reputation: 1

i have a nested list json file and i am using json_normalize to have the data but i am facing TypeError

i have a dataset of 3 objects, i am intrested of the data in object 1 which has, but it have nested lists, the file looks like this :

[{'ob1': [{'values':{'ID':2133 ,'STATUS': closed,'name':'Sara'}}
          {'values':{'ID':5432,'STATUS': closed,'name':'Jon'}}
          {'values':{'ID':5442,'STATUS': closed,'name':'jen'}}}]

I want to expand the data and have a table of ID , STATUS, name.

import pandas as pd
import os
import json
from pandas.io.json import json_normalize
df=pd.read_json('Data.json', lines=True)

df_values = pd.json_normalize(df , 
    record_path=['ob1','values'], 
    meta=[['ID', 'STATUS','name',]],errors='ignore')

the output give an error:

TypeError: string indices must be integers

in this line :

meta=[['ID', 'STATUS','name',]], errors='ignore')

Upvotes: 0

Views: 88

Answers (1)

Finn Hunt
Finn Hunt

Reputation: 103

The JSON provided to the application isn't valid JSON it should look like:

[{"ob1":[{"values":{"ID":2133,"STATUS":"closed","name":"Sara"}},{"values":{"ID":5432,"STATUS":"closed","name":"Jon"}},{"values":{"ID":5442,"STATUS":"closed","name":"Jen"}}]}]

Or like:

[
  {
    "ob1": [
      {
        "values": {
          "ID": 2133,
          "STATUS": "closed",
          "name": "Sara"
        }
      },
      {
        "values": {
          "ID": 5432,
          "STATUS": "closed",
          "name": "Jon"
        }
      },
      {
        "values": {
          "ID": 5442,
          "STATUS": "closed",
          "name": "Jen"
        }
      }
    ]
  }
]

Upvotes: -1

Related Questions