Based on this Q&A a certain JSON value can be found using print data[u'X'][50][u'Z']
data[u'X'] results in:
{
"X" : [ {
"A" : "B",
...
}, {
...
}, {
"C" : "D",
} ]
}
Applying the integer method means that every part that is separated by a comma, e.g. "element" : [ { "name" : "value", ... }, needs to be counted until the required piece has been found, in this case number 50.
What if the JSON structure will be changed in the future? Does this mean that the integer should be updated every time?
In my opinion this method is fragile. How to make it more reliable?
Attempts
print data[u'X'][0] results in:
{u'A': u'B', u'C': u'D'}
while
print data[u'X'][u'A']
results in:
Traceback (most recent call last):
File "test.py", line 9, in <module>
print data[u'beans'][u'modelerType']
TypeError: list indices must be integers, not unicode
print data[u'X'][50][u'Z']will be aKeyError. What is "the integer method" to which you refer? Do you mean indexing into a list (in which case, it certainly does not need "to be counted until the required piece has been found" - indexing isO(1))?