This is my JSONstring:
[{'streamName': 'fsdfomsd_testsdfsdf.mp4', 'vodName': 'fsdfomsd_testsdfsdf.mp4', 'streamId': 'file', 'creationDate': 1642795502009, 'duration': -1, 'fileSize': 0, 'filePath': 'streams/047062868547026247609146.mp4', 'vodId': '047062868547026247609146', 'type': 'uploadedVod'}, {'streamName': 'lol69_testsdfsdf.mp4', 'vodName': 'lol69_testsdfsdf.mp4', 'streamId': 'file', 'creationDate': 1642795501986, 'duration': -1, 'fileSize': 0, 'filePath': 'streams/434226088820102862274153.mp4', 'vodId': '434226088820102862274153', 'type': 'uploadedVod'}, {'streamName': 'testmp_testsdfsdf.mp4', 'vodName': 'testmp_testsdfsdf.mp4', 'streamId': 'file', 'creationDate': 1642795501966, 'duration': -1, 'fileSize': 7, 'filePath': 'streams/476815150179587670305336.mp4', 'vodId': '476815150179587670305336', 'type': 'uploadedVod'}]
How would I run a command in Python for every vodId in the JSON? I am new to Python.
CodePudding user response:
So you have to extact all uniqe vodIds and after that you can run a function per vodId linke
vod_ids ={vod_id for d in your_json if (vod_id := d.get('vodId'))}
for vod_id in vod_ids:
some_function(vod_id)
if your vod_ids don't have to be unique you can replace curly braces with braces which turns it from a set comprehension to a generator expression.
