Q: Parsing a complex JSON dynamically I am working on Twitter json objects, an example of which you can find in this link:
I am using code similar to the one in the link to extract information from the json file. However, in my case, I am trying to parse dynamic twitter data, and some entities have multiple entries or none, in which case, parsing becomes more tricky, and involves huge string operations.
For eg., the key 'coordinates' are present in two to three areas, and ['coordinates']['coordinates'] may either have a value or not have one.
Similarly in hashtags, there may be no hashtag or just one hashtag or multiple entries. If I have multiple hashtags, there are stored as lists, with nested parameters, like indices and text. 
eg., [{u'indices': [81, 91], u'text': u'NYFLC2014'},
{u'indices': [92, 102], u'text': u'NYFLC2013'}]
I will not know them in advance. 
This data comes in dynamically, needs to be stored in the form of xmls, then fed to Apache Solr to be indexed. Is there an efficient parsing method to do this kind of activity? 
I am using python2.7, 

A: You can use ast.literal_eval to parse json data directly to python objects:
import ast
datajson = """[ {u'indices': [81, 91], u'text': u'NYFLC2014'},
                {u'indices': [92, 102], u'text': u'NYFLC2013'}]"""
data = ast.literal_eval(data) 

Output:
data[0]['text']
Out[34]: u'NYFLC2014'

