Python анализирует текст JSON в словарь. Вот полный ответ.
Ваш файл JSON может быть таким, как показано ниже:
[
{"urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"},
{"urlkey": "pt,gov,70ja)/robots.txt", "timestamp": "20190221024013", "url": "http://70ja.gov.pt/robots.txt", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/robotstxt/CC-MAIN-20190221010932-20190221032932-00489.warc.gz", "mime-detected": "text/plain", "offset": "23166", "digest": "5S2OB6LK7EHO74WNBNVLNE6ZBB5VRYTI", "status": "200", "length": "818", "mime": "text/plain"},
{"urlkey": "pt,gov,academiaportuguesadahistoria)/", "timestamp": "20190218105706", "url": "https://academiaportuguesadahistoria.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247484928.52/warc/CC-MAIN-20190218094308-20190218120308-00509.warc.gz", "mime-detected": "text/html", "offset": "498335094", "digest": "EQOJY7DY2YL752S6QCRXLGNDTELPYLD3", "languages": "por", "status": "200", "length": "10240", "mime": "text/html", "charset": "UTF-8"}
]
Анализ такого файла JSON в python3:
import json
with open("jsonDataFile.json") as f:
jsonData = json.loads(f.read())
for array in jsonData:
for key, value in array.items():
print("Key:%s Value:%s" % (key,value))
Если ваш файл не является массивом данных json:
{"urlkey": "pt,gov,70ja)/", "timestamp": "20190221014307", "url": "http://70ja.gov.pt/", "filename": "crawl-data/CC-MAIN-2019-09/segments/1550247497858.46/warc/CC-MAIN-20190221010932-20190221032932-00158.warc.gz", "mime-detected": "text/html", "offset": "4514453", "digest": "LAOPRAYYQUABW3B4ISZINPKETGB4MYRG", "languages": "por", "status": "200", "length": "22629", "mime": "text/html", "charset": "UTF-8"}
Анализ такого файла JSON в python3:
import json
with open("test3.json") as f:
jsonData = json.loads(f.read())
for key, value in jsonData.items():
print("Key:%s Value:%s" % (key,value))