簡體   English   中英

使用python將JSON格式的文件數據加載到表中

[英]Loading JSON format file data to a table using python

我有以下格式的JSON文件。 我打算創建一個Python腳本,將以下文件加載到數據庫表中。

XYZABC  2017-12-04 14:51:39.712 +00:00  {"SourceRelease":"2017_R1","TargetRelease":"2017_R1.1","BlockId":6879246,"TransformType":"BeginBlock"}
XYZABC  2017-12-04 14:51:51.305 +00:00  {"OriginCode":7856,"ReplacementCode":7854,"BlockId":6879246,"TransformType":"Textitem"}
XYZABC  2017-12-04 14:51:51.339 +00:00  {"OriginCode":1497,"ReplacementCode":51143,"BlockId":6879246,"TransformType":"Textitem"}
XYZABC  2017-12-04 14:51:54.608 +00:00  {"OriginCode":7857,"ReplacementCode":7854,"BlockId":6879246,"TransformType":"Textitem"}
XYZABC  2017-12-04 14:52:05.958 +00:00  {"OriginCode":13905,"ReplacementCode":921104,"BlockId":6879246,"TransformType":"Textitem"}
XYZABC  2017-12-04 14:52:06.193 +00:00  {"OriginCode":67021,"ReplacementCode":1532551,"BlockId":6879246,"TransformType":"Textitem"}
XYZABC  2017-12-04 14:52:06.303 +00:00  {"OriginCode":4047,"ReplacementCode":1629834,"BlockId":6879246,"TransformType":"Textitem"}
XYZABC  2017-12-04 14:52:34.640 +00:00  {"Status":"Ok","BlockId":6879246,"TransformType":"EndBlock"}

樣本表列:行

Node            : 'XYZABC'  
DateTime        : '2017-12-04 14:52:06.193'
SourceRelease   : '2017_R1'
TargetRelease   : '2017_R2'
OriginCode      : '4047'
ReplacementCode : '1629834'
BlockId         : '6879246'
TransformType   : 'Textitem'

我希望每一行都被加載到這些列中。 由於我剛接觸Python,因此如果有人可以提供處理該JSON文件格式的基本語法,那將是一個很大的幫助。

問題似乎是此文件不包含純JSON內容。

因此,您需要將文本的每一行分為兩部分:第一部分應讀取Nodedate部分(可能使用regex ),第二部分應使用json.loads()進行解析。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM