我有一个Json和一个数组字段,我想迭代数组,并为数组中包含的每个属性将其拆分为新行或对象
我目前正在使用ApacheNIFI,但我也可以使用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_properties
99999,11,string01
99999,22,string02
99999,33,string03
.
.
.
谢谢你的帮助
您需要将这些空值转换为None或其他Python类型
假设您将空值切换为无
输出
使用NiFi
按此顺序:
EvaluateJsonPath从workorder_id(
$.workorder_id
)创建属性输出将其发送到
$.properties.*
上的拆分Jsonsplitjson的输出将其发送到evaluatejson,您将在那里提取数组
现在,您的每个流都将具有以下属性:
使用此列表使用AttributestoCSV
工单id、id、属性类型id、属性类型名称
合并内容
putfile(保存您的csv)
相关问题 更多 >
编程相关推荐