1

Here is the sample JSON which I am trying to parse in python. I am having hard time parsing through "files": Any help appreciated.

{
    "startDate": "2016-02-19T08:19:30.764-0700",
    "endDate": "2016-02-19T08:20:19.058-07:00",
    "files": [
        {
            "createdOn": "2017-02-19T08:20:19.391-0700",
            "contentType": "text/plain",
            "type": "jpeg",
            "id": "Photoshop",
            "fileUri": "output.log"
        }
    ],
    "status": "OK",
    "linkToken": "-3418849688029673541",
    "subscriberViewers": [
        "null"
    ]
}
2
  • Can you show us what you've tried so far? files is just a list of dictionaries; you would iterate through it like any other list (for fileinfo in data['files']: ...). Commented Feb 28, 2017 at 1:56
  • Please show your effort into solving this issue; it is highly unlikely that other users will help you if they see none of your attempts into solving this issue. Commented Feb 28, 2017 at 2:10

1 Answer 1

1

To print the id of each file in the array:

import json

data = json.loads(rawdata)                                                      

files = data['files']                                                           

for f in files:                                                              
    print(f['id']) 
Sign up to request clarification or add additional context in comments.

1 Comment

...although I would avoid using file as the name of a variable, since you've now masked the builtin file type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.