問題描述
我是 Nifi 的新手,但我有一些 JSON 數據,它是一個數據數組,在每個數組元素中,還有另一個嵌套的數組數據.
I am new to Nifi, but I have some JSON data which is an array of data and in each array element, there is another nested array data.
雖然我能夠獲取文件以加載 JSON,但我遇到的問題如下:
Whilst I am able to get file to load the JSON, where I am struggling is on the following:
- 展平每個數組和嵌套數組 - 包含換行符的嵌套數組存在問題.我已嘗試使用處理器將其刪除,但未將其刪除
- 提取需要的數據
- 要組織提取的數據,將其作為參數傳遞給 Oracle 存儲過程以供執行
我已經使用了 Get File、JoltTransformJson、ExecuteSQL、GetAttributes,但我沒有看到一個結構,其中對于 JSON 數組中的每個元素和展平嵌套 JSON 的屬性列表可以傳遞給存儲過程.
I have used Get File, JoltTransformJson, ExecuteSQL, GetAttributes, but what I am not seeing is a structure where for each element in the array of JSON and for the flatten out nested JSON a list of attributes that can passed on to the Stored Procedure.
誰能提供任何分步指導?
Can anyone give any step by step guidance?
下面是一封關于 JSON 結構的電子郵件,以提供一個想法-
Below is an email of structure of the JSON to give an idea-
[{app_id":1",日期時間":2020-11-30T12:21:25.447430",供應商名稱":abc",doc_id":123345",數據":"{\n header {\n l_Id = { 1 2 3 3 4 5 6 11 }\n identifer = 123456789\n country = GB\n commonIdentifier {\n ident {\n opps = 6175\n etni {\n format =1234567\n }\n }\n commonIdentityId = 0\n }\n sequence = 0\n timeStamp = 20201130002255.0Z\n timeStampQual = timeFound\n }\n data {\n sequence [0] {\n type = type\n content {\n etni {\n params {\n iD = { 1234567 }\n version = version\n identifier = 1234567\n identifier {\n commonidentityid = 30\n id {\n opps = 6175\n netId{\n 格式 = 12563412\n }\n }\n }\n 時間戳 {\n localTime {\ngeneraltime = 20201130122255.000Z\n BSWT = notProvided\n }\n }\n direction = forward\n state = nothing\n release = 9\n nature = ball\n }\n }\n }\n }\n }\n}\n",},{app_id":1",日期時間":2020-11-30T12:21:25.447430",供應商名稱":abc",doc_id":123345",數據":"{\n header {\n l_Id = { 1 2 3 3 4 5 6 11 }\n identifer = 123456789\n country = GB\n commonIdentifier {\n ident {\n opps = 6175\n etni {\n format =1234567\n }\n }\n commonIdentityId = 0\n }\n sequence = 0\n timeStamp = 20201130002255.0Z\n timeStampQual = timeFound\n }\n data {\n sequence [0] {\n type = type\n content {\n etni {\n params {\n iD = { 1234567 }\n version = version\n identifier = 1234567\n identifier {\n commonidentityid = 30\n id {\n opps = 6175\n netId{\n 格式 = 12563412\n }\n }\n }\n 時間戳 {\n localTime {\ngeneraltime = 20201130122255.000Z\n BSWT = notProvided\n }\n }\n direction = forward\n state = nothing\n release = 9\n nature = ball\n }\n }\n }\n }\n }\n}\n",}]
[ { "app_id":"1", "date_time":"2020-11-30T12:21:25.447430", "supplier_name":"abc", "doc_id":"123345", "data":" {\n header {\n l_Id = { 1 2 3 3 4 5 6 11 }\n identifer = 123456789\n country = GB\n commonIdentifier {\n ident {\n opps = 6175\n etni {\n format = 1234567\n }\n }\n commonIdentityId = 0\n }\n sequence = 0\n timeStamp = 20201130002255.0Z\n timeStampQual = timeFound\n }\n data {\n sequence [0] {\n type = type\n contents {\n etni {\n params {\n iD = { 1234567 }\n version = version\n identifier = 1234567\n identifier {\n commonidentityid = 30\n id {\n opps = 6175\n netId {\n format = 12563412\n }\n }\n }\n timeStamp {\n localTime {\n generaltime = 20201130122255.000Z\n BSWT = notProvided\n }\n }\n direction = forward\n state = nothing\n release = 9\n nature = ball\n }\n }\n }\n }\n }\n}\n", }, { "app_id":"1", "date_time":"2020-11-30T12:21:25.447430", "supplier_name":"abc", "doc_id":"123345", "data":" {\n header {\n l_Id = { 1 2 3 3 4 5 6 11 }\n identifer = 123456789\n country = GB\n commonIdentifier {\n ident {\n opps = 6175\n etni {\n format = 1234567\n }\n }\n commonIdentityId = 0\n }\n sequence = 0\n timeStamp = 20201130002255.0Z\n timeStampQual = timeFound\n }\n data {\n sequence [0] {\n type = type\n contents {\n etni {\n params {\n iD = { 1234567 }\n version = version\n identifier = 1234567\n identifier {\n commonidentityid = 30\n id {\n opps = 6175\n netId {\n format = 12563412\n }\n }\n }\n timeStamp {\n localTime {\n generaltime = 20201130122255.000Z\n BSWT = notProvided\n }\n }\n direction = forward\n state = nothing\n release = 9\n nature = ball\n }\n }\n }\n }\n }\n}\n", } ]
推薦答案
有FlattenJSON 處理器如果您想拆分 JSON,則可以使用 JOLT 和一些網站,例如 JOLT 變換
there is the FlattenJSON Processor If you're looking to split the JSON, there is the possibility to use JOLT and some sites such as this JOLT transformation
另一種選擇是相應地拆分 JSON 并使用拆分值.我發現網站 https://jsonpath.com/ 有助于決定拆分的工作方式.我知道這不是一步一步的,但是使用 SplitJSON 處理器,然后可能是 ExtractText 處理器,您將能夠獲得所需的信息.如果不知道數據的確切格式,以及需要哪些數據部分,就很難一步一步地提供準確的數據.
Another option could be to split the JSON accordingly and use the split values. I have found that the website https://jsonpath.com/ is helpful for deciding how the split could work. I know this isnt a step by step, but using the SplitJSON processor and then maybe an ExtractText Processor, you would be able to get the desired information. Without knowing the exact format of the data, and which parts of the data that would be desired, providing an exact step by step will be difficult.
這篇關于Apache Nifi 如何使用嵌套數組 JSON 加載 JSON 并調用 Oracle 存儲過程的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!