2
{
    "duncan_long": {
        "id": "drekaner",
        "name": "Duncan Long",
        "favorite_color": "Blue"
    },
    "kelsea_head": {
        "id": "wagshark",
        "name": "Kelsea Head",
        "favorite_color": "Ping"
    },
    "phoenix_knox": {
        "id": "jikininer",
        "name": "Phoenix Knox",
        "favorite_color": "Green"
    },
    "adina_norton": {
        "id": "slimewagner",
        "name": "Adina Norton",
        "favorite_color": "Red"
    }
}

I am trying to Return a JSON list of all the users excluding the id of the user

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
Tal Mosenzon
  • 41
  • 1
  • 1
  • 5

2 Answers2

2

Assuming your the file in which you have your JSON is called file.json:

import json
with open('file.json') as f:
    d = json.loads(f)
    for key, value in d.items():
        del value['id']
        d[key] = value

Alternative you can use the following:

import json
with open('file.json') as f:
    d = json.loads(f)
    for key, value in d.items():
        value.pop('id', None) // this will not crash if the element has no key 'id'
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
1
import json


with open('file.json') as fin:
    your_structure = json.load(fin)

for value in your_structure.values():
    value.pop('id', None)
Greg Eremeev
  • 1,760
  • 5
  • 23
  • 33