Delete null values from 2d JSON

I have a 2 dimentional json which looks like this:

a =  [
   {
    "photo": null,
    ....
    "webUrl": null,
    "createdByUser": null,
    "lastModifiedByUser": null,
    "id": "154854566458484754...."
    },
    {
    "photo": null,
    ....
    "webUrl": null,
    "createdByUser": null,
    "lastModifiedByUser": null,
    "id": "154854566458484000...."
  },
 ]

how can I remove all null values with the help of python ?

For a one-dimensional Json I get it like this:

filtered_data = {}
for key, value in data.items():
    if value != None:
        filtered_data[key] = value

but for more two-dimensional Json json I don’t get it quite right

   filtered_data = {}
   list          = []

    i = 0
    length = len(data) 
    for i  in range(0, length):
        for key, value in data[i].items():
            if value != None and key != '@odata.type':
                filtered_data[key] = value
        list.append(filtered_data) 

    return list

so I get several times the last entry of the json

Answer

how can I remove all null values with the help of python ?

The idea is to scan the data and collect not None values. Try the below

import json

json_str = '''[
   {
    "photo": null,
    "webUrl": null,
    "createdByUser": null,
    "lastModifiedByUser": null,
    "id": "154854566458484754...."
    },
    {
    "photo": null,
    "webUrl": null,
    "createdByUser": null,
    "lastModifiedByUser": null,
    "id": "154854566458484000...."
  }
 ]'''
data = json.loads(json_str)
new_data = []
for entry in data:
    new_data.append({})
    for k, v in entry.items():
        if v is not None:
            new_data[-1][k] = v
print(new_data)

output

[{'id': '154854566458484754....'}, {'id': '154854566458484000....'}]