I get such a fragment of an array of JSON, the question is, how can I get the name (?) Of the array through Python Ie, a number that will stand still 1477770720169

{ '1477770720169': { 'rights': { '1477770395835': { 'ua_company_name': '', 'eng_fullname': '', 'ukr_company_name': '', 'ukr_middlename_extendedstatus': '', 'citizen': '', 'ukr_firstname': '', 'ua_lastname': '', 'ua_houseNum_extendedstatus': '', 'ua_housePartNum_extendedstatus': '', 'ua_firstname': '', 'eng_lastname': '', 'eng_firstname': '', 'percent-ownership': '', 'ua_apartmentsNum_extendedstatus': '', 'otherOwnership': '', 'ua_middlename_extendedstatus': '', 'ua_streetType': '[Конфіденційна інформація]', 'rights_cityPath': '', 'eng_company_name': '', 'ua_middlename': '', 'postCode': '[Конфіденційна інформація]', 'ukr_fullname': '', 'ua_city': '', 'eng_postCode': '', 'ua_street': '[Конфіденційна інформація]', 'ua_postCode': '', 'ua_postCode_extendedstatus': '', 'eng_middlename_extendedstatus': '', 'eng_middlename': '', 'rightBelongs': '1477770395835', 'eng_postCode_extendedstatus': '', 'ukr_middlename': '', 'percent-ownership_extendedstatus': '1', 'ua_street_extendedstatus': '', 'ownershipType': 'Спільна власність', 'ukr_lastname': '' } }, 'costAssessment_extendedstatus': '1', 'ua_postCode': '27403', 'totalArea': '48', 'otherObjectType': '', 'iteration': '1477770720169', 'ua_housePartNum_extendedstatus': '1', 'city': '[Конфіденційна інформація]', 'costAssessment': '', 'ua_streetType': '[Конфіденційна інформація]', 'ua_cityType': "Знам'янка / Кіровоградська область / Україна", 'owningDate': '14.10.2004', 'postCode': '[Конфіденційна інформація]', 'costDate': '9265', 'cityPath': '[Конфіденційна інформація]', 'person': '1477770395835', 'ua_apartmentsNum_extendedstatus': '1', 'country': '1', 'district': '[Конфіденційна інформація]', 'region': '[Конфіденційна інформація]', 'ua_street': '[Конфіденційна інформація]', 'objectType': 'Житловий будинок' } } 
  • print (''. join (x for x in s.keys ())), where s is a dictionary. You can pre-assign the value and check. - Dmitry Erohin

2 answers 2

In the question you do not have JSON (json does not use single quotes for strings). You have a textual representation of a dictionary (associative arrays are called "dictionary" in Python), then how it is defined in Python in the source code.

To print all the keys in a given dictionary d , it is enough to bypass it:

 for key in d: print(key) 

Or a space: print(*d) .

Python dictionaries are an unordered collection of key / value pairs. If you want to get the first key (no matter what), from the dictionary, pull out:

 >>> next(iter(d)) '1477770720169' 
     >>> a = {'1477770720169': {'rights': {'1477770395835': {'ua_company_name': '', 'eng_fullname': '', 'ukr_company_name': '', 'ukr_middlename_extendedstatus': '', 'citizen': '', 'ukr_firstname': '', 'ua_lastname': '', 'ua_houseNum_extendedstatus': '', 'ua_housePartNum_extendedstatus': '', 'ua_firstname': '', 'eng_lastname': '', 'eng_firstname': '', 'percent-ownership': '', 'ua_apartmentsNum_extendedstatus': '', 'otherOwnership': '', 'ua_middlename_extendedstatus': '', 'ua_streetType': '[Конфіденційна інформація]', 'rights_cityPath': '', 'eng_company_name': '', 'ua_middlename': '', 'postCode': '[Конфіденційна інформація]', 'ukr_fullname': '', 'ua_city': '', 'eng_postCode': '', 'ua_street': '[Конфіденційна інформація]', 'ua_postCode': '', 'ua_postCode_extendedstatus': '', 'eng_middlename_extendedstatus': '', 'eng_middlename': '', 'rightBelongs': '1477770395835', 'eng_postCode_extendedstatus': '', 'ukr_middlename': '', 'percent-ownership_extendedstatus': '1', 'ua_street_extendedstatus': '', 'ownershipType': 'Спільна власність', 'ukr_lastname': ''}}, 'costAssessment_extendedstatus': '1', 'ua_postCode': '27403', 'totalArea': '48', 'otherObjectType': '', 'iteration': '1477770720169', 'ua_housePartNum_extendedstatus': '1', 'city': '[Конфіденційна інформація]', 'costAssessment': '', 'ua_streetType': '[Конфіденційна інформація]', 'ua_cityType': "Знам'янка / Кіровоградська область / Україна", 'owningDate': '14.10.2004', 'postCode': '[Конфіденційна інформація]', 'costDate': '9265', 'cityPath': '[Конфіденційна інформація]', 'person': '1477770395835', 'ua_apartmentsNum_extendedstatus': '1', 'country': '1', 'district': '[Конфіденційна інформація]', 'region': '[Конфіденційна інформація]', 'ua_street': '[Конфіденційна інформація]', 'objectType': 'Житловий будинок'}} >>> a.keys() ['1477770720169'] >>> a.keys()[0] '1477770720169' 

    So?

    • In Python 3 will not work - andreymal
    • >>> a.keys () dict_keys (['1477770720169']) >>> a.keys () [0] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError : 'dict_keys' object does not support indexing - Dmitry Erohin