Question Details

No question body available.

Tags

python json pandas dataframe

Answers (2)

March 20, 2026 Score: 2 Rep: 28,415 Quality: Medium Completeness: 60%

Using recordpath=['reports'] does roughly what you want. The only exception is that it doesn't capture the reportid column. You can add a line to provide that column.

import pandas as pd
import json

This is a file containing the JSON from the question.

If you already have the JSON loaded into the variable 'data'

you don't need this step

with open('test1165.json', 'rb') as f: data = json.load(f)

reportdf = pd.jsonnormalize(data, recordpath=['reports']) reportdf.insert(0, 'reportid', data['id'])

print(reportdf.tostring())

Printing reportdf gives the following:

report
id body type outcome.comments outcome.id outcome.status.failed.both outcome.status.failed.human outcome.status.failed.auto outcome.status.failed.total outcome.status.open.both outcome.status.open.human outcome.status.open.auto outcome.status.open.total outcome.status.passed.both outcome.status.passed.human outcome.status.passed.auto outcome.status.passed.total outcome.status.code.input outcome.status.code.output outcome.status.code.canceled outcome.status.total 0 12345 \n\nGeneral report text. outcome [] 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 12345 \n\nGeneral report text. outcome [] 2 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1
March 20, 2026 Score: 1 Rep: 573 Quality: Low Completeness: 50%

Using recordpath='reports' and meta=['id'] then rearrange and rename columns to get the desired dataframe.

This approach also works if you have multiple (a list of) reports in the json data.

import json
import pandas as pd

with open("data.json") as f: data = json.load(f)

df = pd.jsonnormalize(data, recordpath='reports', meta=['id'])

#rearrange and rename columns df.insert(0, 'report
id', df.pop('id')) df.insert(1, 'outcome.id', df.pop('outcome.id')) print(df.tostring())