Search code examples
pythonjsonpandasio

Can a json file contain a key in the nth element that is not in preceding elements?


Is this a legitimate json structure? How would I access subDictkey at an arbitrary point in someList? (e.g. not someList[4]['someList']) Must 'subDictkey' exist in every element of 'someList'?

{ 
    'dict': {
        'someList': [
           {},
           {},
           {},
           {},
           {'subDictkey':
                'sublist':[]
           },
        ]
    }
 }

Solution

  • OK, I'll take silence to mean this would be terrible and you shouldn't do it.

    I would assume that elements should be should be consistent throughout the list and not just 'appear' in the nth element.