Convert Json array into csv using apache NifiCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?Can comments be used in JSON?How to append something to an array?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?Loop through an array in JavaScriptHow do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

Has the United States ever had a non-Christian President?

How can a hefty sand storm happen in a thin atmosphere like Martian?

Why does blending blueberries, milk, banana and vanilla extract cause the mixture to have a yogurty consistency?

Blender 2.80 Remove double vertices option gone

Can full drive backup be used instead of MSSQL database backup?

Can I hide the part of long lines that exceeds the visual line?

Why are oscilloscope input impedances so low?

My first C++ game (snake console game)

Why is "breaking the mould" positively connoted?

Is there a word that describes the unjustified use of a more complex word?

Would a "Permanence" spell in 5e be overpowered?

Undefined Control Sequence for my 0-norm

Why would a military not separate its forces into different branches?

Would a small hole in a Faraday cage drastically reduce its effectiveness at blocking interference?

Why does sound not move through a wall?

Is it normal for gliders not to have attitude indicators?

Is any special diet an effective treatment of autism?

Will a God Eternal enchanted with Deep Freeze shuffle back into the deck if it dies?

How to pass query parameters in URL in Salesforce Summer 19 Release?

In Futurama, how many beings has Leela slept with?

Where to draw the line between quantum mechanics theory and its interpretation(s)?

Endgame puzzle: How to avoid stalemate and win?

Which US defense organization would respond to an invasion like this?

GitLab account hacked and repo wiped



Convert Json array into csv using apache Nifi


Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?Can comments be used in JSON?How to append something to an array?How can I pretty-print JSON in a shell script?What is the correct JSON content type?Why does Google prepend while(1); to their JSON responses?Loop through an array in JavaScriptHow do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm looking to convert JSON with an array to csv format. The number of elements inside the array is dynamic for each row. I tried using this flow, ( attached the flow file xml on the post ).



GetFile --> ConvertRecord --> UpdateAttribute --> PutFile



Are there any other alternatives?



JSON format:



 "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"


Expected output in 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


Output from the attached flow:
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 -- I am using JSONTreereader and CSVRecordSSetwriter configurations as below:
enter image description here



JSONTreereader Controler service config:
enter image description here
CSVRecordSetwriter controller service config:
enter image description here
AvroschemaRegistry Controller service config:
enter image description here



Avro schema :
"name": "myschema", "type": "record", "namespace": "myschema", "fields": ["name": "LogData","type": "name": "LogData", "type": "record", "fields": [ "name": "Location", "type": "string", "name": "product", "type": "string" ],"name": "Outcome","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" ] ]










share|improve this question




























    0















    I'm looking to convert JSON with an array to csv format. The number of elements inside the array is dynamic for each row. I tried using this flow, ( attached the flow file xml on the post ).



    GetFile --> ConvertRecord --> UpdateAttribute --> PutFile



    Are there any other alternatives?



    JSON format:



     "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"


    Expected output in 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


    Output from the attached flow:
    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 -- I am using JSONTreereader and CSVRecordSSetwriter configurations as below:
    enter image description here



    JSONTreereader Controler service config:
    enter image description here
    CSVRecordSetwriter controller service config:
    enter image description here
    AvroschemaRegistry Controller service config:
    enter image description here



    Avro schema :
    "name": "myschema", "type": "record", "namespace": "myschema", "fields": ["name": "LogData","type": "name": "LogData", "type": "record", "fields": [ "name": "Location", "type": "string", "name": "product", "type": "string" ],"name": "Outcome","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" ] ]










    share|improve this question
























      0












      0








      0








      I'm looking to convert JSON with an array to csv format. The number of elements inside the array is dynamic for each row. I tried using this flow, ( attached the flow file xml on the post ).



      GetFile --> ConvertRecord --> UpdateAttribute --> PutFile



      Are there any other alternatives?



      JSON format:



       "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"


      Expected output in 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


      Output from the attached flow:
      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 -- I am using JSONTreereader and CSVRecordSSetwriter configurations as below:
      enter image description here



      JSONTreereader Controler service config:
      enter image description here
      CSVRecordSetwriter controller service config:
      enter image description here
      AvroschemaRegistry Controller service config:
      enter image description here



      Avro schema :
      "name": "myschema", "type": "record", "namespace": "myschema", "fields": ["name": "LogData","type": "name": "LogData", "type": "record", "fields": [ "name": "Location", "type": "string", "name": "product", "type": "string" ],"name": "Outcome","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" ] ]










      share|improve this question














      I'm looking to convert JSON with an array to csv format. The number of elements inside the array is dynamic for each row. I tried using this flow, ( attached the flow file xml on the post ).



      GetFile --> ConvertRecord --> UpdateAttribute --> PutFile



      Are there any other alternatives?



      JSON format:



       "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"


      Expected output in 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


      Output from the attached flow:
      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 -- I am using JSONTreereader and CSVRecordSSetwriter configurations as below:
      enter image description here



      JSONTreereader Controler service config:
      enter image description here
      CSVRecordSetwriter controller service config:
      enter image description here
      AvroschemaRegistry Controller service config:
      enter image description here



      Avro schema :
      "name": "myschema", "type": "record", "namespace": "myschema", "fields": ["name": "LogData","type": "name": "LogData", "type": "record", "fields": [ "name": "Location", "type": "string", "name": "product", "type": "string" ],"name": "Outcome","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" ] ]







      arrays json apache-nifi jsonpath






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 2:57









      vishwanatha handadivishwanatha handadi

      124




      124






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Try this spec in JoltTransformJSON before ConvertRecord:



           
          "operation": "shift",
          "spec":
          "Outcome":
          "*":
          "@(3,LogData.Location)": "[#2].location",
          "@(3,LogData.product)": "[#2].product",
          "@(3,attr.vers)": "[#2].vers",
          "@(3,attr.datetime)": "[#2].datetime",
          "*": "[#2].&"




          ]```





          share|improve this answer























          • Thanks a ton @mattyb for the help. This works like a charm. One question: If i have 1300 + array elements inside Outcome:[], will the jolt transform works well or will there be any overhead while converting 1 incoming json record to 1300+ json records?

            – vishwanatha handadi
            Mar 27 at 13:58











          • Not sure what you mean by overhead, but I can tell you that all 1300+ flow files will be transferred at the same time, once they are all done processing and the session is committed.

            – mattyb
            Mar 29 at 19:28


















          1














          Seems that you need to performa JoltTransform before convert to CSV, if not is not going to work.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310186%2fconvert-json-array-into-csv-using-apache-nifi%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Try this spec in JoltTransformJSON before ConvertRecord:



             
            "operation": "shift",
            "spec":
            "Outcome":
            "*":
            "@(3,LogData.Location)": "[#2].location",
            "@(3,LogData.product)": "[#2].product",
            "@(3,attr.vers)": "[#2].vers",
            "@(3,attr.datetime)": "[#2].datetime",
            "*": "[#2].&"




            ]```





            share|improve this answer























            • Thanks a ton @mattyb for the help. This works like a charm. One question: If i have 1300 + array elements inside Outcome:[], will the jolt transform works well or will there be any overhead while converting 1 incoming json record to 1300+ json records?

              – vishwanatha handadi
              Mar 27 at 13:58











            • Not sure what you mean by overhead, but I can tell you that all 1300+ flow files will be transferred at the same time, once they are all done processing and the session is committed.

              – mattyb
              Mar 29 at 19:28















            1














            Try this spec in JoltTransformJSON before ConvertRecord:



             
            "operation": "shift",
            "spec":
            "Outcome":
            "*":
            "@(3,LogData.Location)": "[#2].location",
            "@(3,LogData.product)": "[#2].product",
            "@(3,attr.vers)": "[#2].vers",
            "@(3,attr.datetime)": "[#2].datetime",
            "*": "[#2].&"




            ]```





            share|improve this answer























            • Thanks a ton @mattyb for the help. This works like a charm. One question: If i have 1300 + array elements inside Outcome:[], will the jolt transform works well or will there be any overhead while converting 1 incoming json record to 1300+ json records?

              – vishwanatha handadi
              Mar 27 at 13:58











            • Not sure what you mean by overhead, but I can tell you that all 1300+ flow files will be transferred at the same time, once they are all done processing and the session is committed.

              – mattyb
              Mar 29 at 19:28













            1












            1








            1







            Try this spec in JoltTransformJSON before ConvertRecord:



             
            "operation": "shift",
            "spec":
            "Outcome":
            "*":
            "@(3,LogData.Location)": "[#2].location",
            "@(3,LogData.product)": "[#2].product",
            "@(3,attr.vers)": "[#2].vers",
            "@(3,attr.datetime)": "[#2].datetime",
            "*": "[#2].&"




            ]```





            share|improve this answer













            Try this spec in JoltTransformJSON before ConvertRecord:



             
            "operation": "shift",
            "spec":
            "Outcome":
            "*":
            "@(3,LogData.Location)": "[#2].location",
            "@(3,LogData.product)": "[#2].product",
            "@(3,attr.vers)": "[#2].vers",
            "@(3,attr.datetime)": "[#2].datetime",
            "*": "[#2].&"




            ]```






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 at 23:27









            mattybmattyb

            8,1411018




            8,1411018












            • Thanks a ton @mattyb for the help. This works like a charm. One question: If i have 1300 + array elements inside Outcome:[], will the jolt transform works well or will there be any overhead while converting 1 incoming json record to 1300+ json records?

              – vishwanatha handadi
              Mar 27 at 13:58











            • Not sure what you mean by overhead, but I can tell you that all 1300+ flow files will be transferred at the same time, once they are all done processing and the session is committed.

              – mattyb
              Mar 29 at 19:28

















            • Thanks a ton @mattyb for the help. This works like a charm. One question: If i have 1300 + array elements inside Outcome:[], will the jolt transform works well or will there be any overhead while converting 1 incoming json record to 1300+ json records?

              – vishwanatha handadi
              Mar 27 at 13:58











            • Not sure what you mean by overhead, but I can tell you that all 1300+ flow files will be transferred at the same time, once they are all done processing and the session is committed.

              – mattyb
              Mar 29 at 19:28
















            Thanks a ton @mattyb for the help. This works like a charm. One question: If i have 1300 + array elements inside Outcome:[], will the jolt transform works well or will there be any overhead while converting 1 incoming json record to 1300+ json records?

            – vishwanatha handadi
            Mar 27 at 13:58





            Thanks a ton @mattyb for the help. This works like a charm. One question: If i have 1300 + array elements inside Outcome:[], will the jolt transform works well or will there be any overhead while converting 1 incoming json record to 1300+ json records?

            – vishwanatha handadi
            Mar 27 at 13:58













            Not sure what you mean by overhead, but I can tell you that all 1300+ flow files will be transferred at the same time, once they are all done processing and the session is committed.

            – mattyb
            Mar 29 at 19:28





            Not sure what you mean by overhead, but I can tell you that all 1300+ flow files will be transferred at the same time, once they are all done processing and the session is committed.

            – mattyb
            Mar 29 at 19:28













            1














            Seems that you need to performa JoltTransform before convert to CSV, if not is not going to work.






            share|improve this answer



























              1














              Seems that you need to performa JoltTransform before convert to CSV, if not is not going to work.






              share|improve this answer

























                1












                1








                1







                Seems that you need to performa JoltTransform before convert to CSV, if not is not going to work.






                share|improve this answer













                Seems that you need to performa JoltTransform before convert to CSV, if not is not going to work.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 24 at 12:17









                Óscar AndreuÓscar Andreu

                1,176728




                1,176728



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310186%2fconvert-json-array-into-csv-using-apache-nifi%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해