1

I have an existing json file and want to create a list for a specific field how do I create it? I went through other stackoverflow questions specific to python, but not quite what I was looking for.

Current JSON file:

[{"team_name": "Journalist", "team_members": "Ali Smith, Jon Doe"},
{"team_name": "Journalist & Media", "team_members": "A Smith, Micheal P"},
{"team_name": "Photography", "team_members": "Micheal P, Adam A"}]

Final output file:

[{"team_name": "Journalist", "team_members": ["Ali Smith", "Jon Doe"]},
{"team_name": "Journalist & Media", "team_members": ["A Das", "Micheal P"]},
{"team_name": "Photography", "team_members": ["Micheal P", "Adam A"}]
martineau
  • 119,623
  • 25
  • 170
  • 301
sharp
  • 2,140
  • 9
  • 43
  • 80
  • 1
    Other than splitting on ", "? – Ignacio Vazquez-Abrams May 15 '18 at 18:33
  • 1
    `[s.strip() for s in 'this, string, here'.split(',')]` – Brendan Abel May 15 '18 at 18:36
  • from @BrendanAbel comment: Here is how I was able to get it: ```with open('test.json') as json_data: data = json.load(json_data) print('All data:', '\n',data) print ('') for element in data: element['team_members'] = [s.strip() for s in element['team_members'].split(',')] print(element)``` – sharp May 15 '18 at 19:11

0 Answers0