How to Parse XML like Dictonary in Python
Question: I am new to Python and I been trying to get below fnames Parsed and having
hard time doing so.

I need to parse below fNames...

    
    
    {"values":
        {"entries":"uri", "type":"xs:string", "unique-value":
            [{"entry":1, "fName":"\/abc.txt"},
             {"entry":1, "fName":"\/def.txt"},
             {"entry":1, "fName":"\/xyz.txt"},
             {"entry":1, "fName":"\/file.doc"},
             {"entry":1, "fName":"\/file2.txt"}
            ]
        }
    }
    

Here is my Code:

    
    
    for entry in j['values']['entries']:
        print entry['entry']['fName']
    


Answer: I am not enterily sure what you mean with parse, but if you simply want to get
the values of fName, you could simply loop through list like this:

    
    
    import json
    text = """{.....}"""
    json_data = json.loads(text)
    for value in json_data['values']['unique-value']:
        print "entry:", value['entry'], "-- fName:", value['fName']
    

**Output:**

    
    
    entry: 1 -- fName: /abc.txt
    entry: 1 -- fName: /def.txt
    entry: 1 -- fName: /xyz.txt
    entry: 1 -- fName: /file.doc
    entry: 1 -- fName: /file2.txt
    

The reason that your code didn't work was because both `entry` and `fName` are
both key/values from the same dictionary. This means that for your code to
work, the json layout would have to look like this:

    
    
    [{"entry": {"fName": "/abc.txt"}}, {"entry": {"fName": "/def.txt"}}]
    

