processing nested json data

Hi,
i need help to flatten the below json data by removing from “Answers” where “answer1” is null(‘’) :

“body”: [
{
“responseId”: 1,
“answers”: [
{
“answer1”: “”,
“questionId”: “r67be312f34474793b802cdb35a719e5f”
},
{
“answer1”: {
“id”: 1,
“order”: 3,
“displayText”: “Fair”

                },
                "questionId": "r932bd3d18d4e4af2ba8174333c86a5dc"
            },
            {
                "answer1": "7 to 9 years",
                "questionId": "r44d182a9e27d4b0c902862362c2da4db"
            },

            {
                "answer1": {
                    "id": 6,
                    "order": 1751924912753,
                    "displayText": "N/A"

                },
                "questionId": "rc4e8608191e24d76bf1c568a384f23bf"
            }
 ] 
 }
 ]

any help is appreciated - thanks.

While I’m not entirely sure why your JSON is organized the way it is. The general approach to processing JSON data is to load it as a dictionary in Python, and then use a loop to go through each item. When you find an entry where a value is null or empty (like ""), you can simply skip or remove that entry to clean things up.
For example:

processed_data = {"body" : []}
for i in data['body']:
    filtered_answers = []
    for j in i['answers']:
        if j['answer1'] != "":
            filtered_answers.append(answer)
    if filtered_answers:
        processed_data['body'].append({
            "responseId": item['responseId'],
            "answers": filtered_answers
        })