我正在使用下面的代码读取JSON文件,但它仅读取第一个json字符串。
我又如何根据JSON创建数据框
def load_json_multiple(segments):
chunk = ""
for segment in segments:
chunk += segment
try:
yield json.loads(chunk)
chunk = ""
except ValueError:
pass
with open('Splunk_raw_wtd_30082018.json') as f:
for parsed_json in load_json_multiple(f):
print (parsed_json)
这是示例数据。
{"preview":false,"result":{"_raw":"{\"event_time\":\"2018-08-24T04:38:09.182Z\",\"event_info\":{\"healthcheck_terms_start\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"9fdfb794-7408-44e2-8d9e-3001026fb11e\"},\"event_id\":\"8b7c1cf1-cdb4-4cef-a508-d0c0c6a0a048\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_terms_start\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"ondevice\"],\"framework_id\":\"2a1ee0ea-a657-4f84-af5f-c910f3a68766\",\"source_ip\":\"99.235.120.15\"}\n{\"event_time\":\"2018-08-24T04:39:58.647Z\",\"event_info\":{\"healthcheck_minimize\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"9fdfb794-7408-44e2-8d9e-3001026fb11e\"},\"event_id\":\"d679654a-9458-4177-a4a9-48e9a38f0010\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_minimize\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"ondevice\"],\"framework_id\":\"2a1ee0ea-a657-4f84-af5f-c910f3a68766\",\"source_ip\":\"99.235.120.15\"}","_time":"2018-08-24T07:38:09.182+0300","closed_txn":"0","context.applicationSessionGuid":"9fdfb794-7408-44e2-8d9e-3001026fb11e","context.domain":"applications_user_healthcheck","date_hour":"4","date_mday":"24","date_minute":["38","39"],"date_month":"august","date_second":["58","9"],"date_wday":"friday","date_year":"2018","date_zone":"0","duration":"109.465","event_id":["8b7c1cf1-cdb4-4cef-a508-d0c0c6a0a048","d679654a-9458-4177-a4a9-48e9a38f0010"],"event_severity":"info","event_source{}":["digital","info","ondevice","Bell"],"event_time":["2018-08-24T04:38:09.182Z","2018-08-24T04:39:58.647Z"],"event_type":["healthcheck_minimize","healthcheck_terms_start"],"eventcount":"2","field_match_sum":"2","framework_id":"2a1ee0ea-a657-4f84-af5f-c910f3a68766","host":"in.prod_splunk_heavy_forwarders.mce-sys.com:8088","index":"info_Bell_digital_ondevice","linecount":"2","source":"http:shpritzer","source_ip":"99.235.120.15","sourcetype":"shpritzer_json","splunk_server":["indexer-0","indexer-1"]}}
{"preview":false,"result":{"_raw":"{\"event_time\":\"2018-08-24T04:34:31.696Z\",\"event_info\":{\"healthcheck_app_launch\":{\"device\":{\"make\":\"samsung\",\"model\":\"SM-G960W\",\"nickname\":\"\",\"os_version\":\"8.0.0/G960WVLU2ARF7\",\"os\":\"Android\"},\"app_version\":\"1.2.4\",\"first_launch\":true}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"d71bf4ff-00e1-4e79-871b-f4ef59bf21d9\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_app_launch\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:34:31.708Z\",\"event_info\":{\"healthcheck_terms_start\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"74573d9c-b08f-4006-9e26-65b528f71412\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_terms_start\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:34:34.516Z\",\"event_info\":{\"healthcheck_terms_end\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"e369903f-5f91-4553-88ee-a3f316bae13b\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_terms_end\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:34:34.576Z\",\"event_info\":{\"healthcheck_data_usage_access_start\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"57a149f8-0783-41ba-b2f2-5034d04323d5\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_data_usage_access_start\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:34:39.252Z\",\"event_info\":{\"healthcheck_data_usage_access_end\":{\"action\":\"continue\"}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"cebfc9a0-7aa9-42b7-b9d2-3b2adff636a2\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_data_usage_access_end\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:34:39.750Z\",\"event_info\":{\"healthcheck_minimize\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"122dec83-4be0-4175-a1fe-cbcbb9e0ef35\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_minimize\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:35:02.605Z\",\"event_info\":{\"healthcheck_maximize\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"890b33c4-845f-43ec-90fe-035bb9f33dae\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_maximize\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:35:09.789Z\",\"event_info\":{\"healthcheck_data_usage_access_start\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"86c29bec-db0f-4dfc-8662-c3bd5675e47b\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_data_usage_access_start\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:35:16.416Z\",\"event_info\":{\"healthcheck_data_usage_access_end\":{\"action\":\"continue\"}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"31588ffe-9a86-4a63-ae24-64aaf1f62d79\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_data_usage_access_end\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:35:16.722Z\",\"event_info\":{\"healthcheck_minimize\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"863128b8-0bef-47ff-b9aa-30a7568daa82\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_minimize\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.74\"}\n{\"event_time\":\"2018-08-24T04:35:16.722Z\",\"event_info\":{\"healthcheck_minimize\":{}},\"context\":{\"domain\":\"applications_user_healthcheck\",\"applicationSessionGuid\":\"16c9f5b0-1a67-45da-a015-f69be6158811\"},\"event_id\":\"863128b8-0bef-47ff-b9aa-30a7568daa82\",\"event_severity\":\"info\",\"event_type\":\"healthcheck_minimize\",\"event_source\":[\"info\",\"Bell\",\"digital\",\"onDevice\"],\"framework_id\":\"e608762f-de6d-4ff2-8e14-458fbf3c7379\",\"source_ip\":\"209.171.88.234\"}","_time":"2018-08-24T07:34:31.696+0300","closed_txn":"0","context.applicationSessionGuid":"16c9f5b0-1a67-45da-a015-f69be6158811","context.domain":"applications_user_healthcheck","date_hour":"4","date_mday":"24","date_minute":["34","35"],"date_month":"august","date_second":["16","2","31","34","39","9"],"date_wday":"friday","date_year":"2018","date_zone":"0","duration":"45.026","event_id":["122dec83-4be0-4175-a1fe-cbcbb9e0ef35","31588ffe-9a86-4a63-ae24-64aaf1f62d79","57a149f8-0783-41ba-b2f2-5034d04323d5","74573d9c-b08f-4006-9e26-65b528f71412","863128b8-0bef-47ff-b9aa-30a7568daa82","86c29bec-db0f-4dfc-8662-c3bd5675e47b","890b33c4-845f-43ec-90fe-035bb9f33dae","cebfc9a0-7aa9-42b7-b9d2-3b2adff636a2","d71bf4ff-00e1-4e79-871b-f4ef59bf21d9","e369903f-5f91-4553-88ee-a3f316bae13b"],"event_severity":"info","event_source{}":["digital","info","onDevice","Bell"],"event_time":["2018-08-24T04:34:31.696Z","2018-08-24T04:34:31.708Z","2018-08-24T04:34:34.516Z","2018-08-24T04:34:34.576Z","2018-08-24T04:34:39.252Z","2018-08-24T04:34:39.750Z","2018-08-24T04:35:02.605Z","2018-08-24T04:35:09.789Z","2018-08-24T04:35:16.416Z","2018-08-24T04:35:16.722Z"],"event_type":["healthcheck_app_launch","healthcheck_data_usage_access_end","healthcheck_data_usage_access_start","healthcheck_maximize","healthcheck_minimize","healthcheck_terms_end","healthcheck_terms_start"],"eventcount":"11","field_match_sum":"11","framework_id":"e608762f-de6d-4ff2-8e14-458fbf3c7379","host":"in.prod_splunk_heavy_forwarders.mce-sys.com:8088","index":"info_Bell_digital_ondevice","linecount":"11","source":"http:shpritzer","source_ip":["209.171.88.234","209.171.88.74"],"sourcetype":"shpritzer_json","splunk_server":["indexer-0","indexer-1"]}}