使用Nifi将Json数组转换为CSV

时间:2019-03-22 19:19:10

标签: arrays json apache-nifi

我正在寻找将数组转换为CSV格式的JSON。每一行中数组内部元素的数量是动态的。我尝试使用此流程((将流程文件xml附加在帖子上)。

GetFile-> ConvertRecord-> UpdateAttribute-> PutFile

还有其他选择吗?

JSON格式:

{  
   "LogData":{  
      "Location":"APAC",
      "product":"w1"
   },
   "Outcome":[  
      {  
         "limit":"0",
         "pri":"3",
         "result":"pass"
      },
      {  
         "limit":"1",
         "pri":"2",
         "result":"pass"
      },
      {  
         "limit":"5",
         "priority":"1",
         "result":"fail"
      }
   ],
   "attr":{  
      "vers":"1",
      "datetime":"2018-01-10 00:36:00"
   }
}

csv中的预期输出:

location,   product,    limit,  pri,    result, vers,   datetime
APAC        w1          0       3       pass    1       2018-01-10 00:36:00
APAC        w1          1       2       pass    1       2018-01-10 00:36:00
APAC        w1          5       1       fail    1       2018-01-10 00:36:00

附件流的输出:

LogData,Outcome,attr
"MapRecord[{product=w1, Location=APAC}]","[MapRecord[{limit=0, result=pass, pri=3}], MapRecord[{limit=1, result=pass, pri=2}], MapRecord[{limit=5, result=fail}]]","MapRecord[{datetime=2018-01-10 00:36:00, vers=1}]"

enter image description here

ConvertRecord配置: enter image description here

JSONTReeReader控制器服务配置: enter image description here CSVRecordSetWriter控制器服务配置: enter image description here Avroschmeregistry Contoller服务配置: enter image description here

Avro模式:     {“ name”:“ myschema”,“ type”:“ record”,“ namespace”:“ myschema”,“ fields”:[{“ name”:“ LogData”,“ type”:{“ name”:“ LogData “,”类型“:”记录“,”字段“:[{”名称“:”位置“,”类型“:”字符串“},{”名称“:”产品“,”类型“:”字符串“} ]}},{“ name”:“结果”,“ type”:{“ type”:“ array”,“ items”:{“ name”:“ Outcome_record”,“ type”:“ record”,“ fields” :[{“ name”:“ limit”,“ type”:“ string”},{“ name”:“ pri”,“ type”:[“ string”,“ null”]},{“ name”:“ result“,” type“:” string“}]}}},{” name“:” attr“,” type“:{” name“:” attr“,” type“:” record“,” fields“: [{“ name”:“ vers”,“ type”:“ string”},{“ name”:“ datetime”,“ type”:“ string”}]}}]}

0 个答案:

没有答案