我有一個帶有數組字段的 Json,我想迭代該數組并將其拆分為數組中包含的每個屬性的新行或對象。我目前正在使用 Apache Nifi,但我也可以使用 python 腳本。我的輸入數據是:{ "workorder_id" : "99999", "properties" : [ { "id" : "11", "propertyType" : { "id" : "55834595398", "name" : "action" }, "stringValue" : "string01", "nodeValue" : null }, { "id" : "22", "propertyType" : { "id" : "55834595419", "name" : "Tipo" }, "stringValue" : "string02", "nodeValue" : null }, { "id" : "33", "propertyType" : { "id" : "44", "name" : "Action2" }, "stringValue" : "string02", "nodeValue" : null }, { "id" : "55", "propertyType" : { "id" : "55834595400", "name" : "Action3" }]}輸出可以是 Json 或 csv。例如在 csv 中:使用相同的 workorder_id 作為鍵workorder_id,id_properties,stringValue_properties99999,11,string0199999,22,string0299999,33,string03...感謝您的幫助
1 回答

一只甜甜圈
TA貢獻1836條經驗 獲得超5個贊
使用 NiFi
按此順序:
EvaluateJsonPath 從 workorder_id (
$.workorder_id
)創建屬性輸出將它發送到 Split Json
$.properties.*
splitjson 的輸出將它發送到 evaluatejson,您將在其中提取數組。
id = $.id propertyType_id = $.propertyType.id propertyType_name = $.propertyType.name
現在您的每個流程都將帶有此屬性:
workorder_id,id,propertyType_id,propertyType_name
使用此列表使用 AttributestoCSV
workorder_id,id,propertyType_id,propertyType_name
合并內容
putfile(保存你的 csv)
添加回答
舉報
0/150
提交
取消