Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
jenn11439
Contributor
Contributor

convert a row in a json file

Hi, I am using Talend cloud DI 7.3. I am a newbie in using component tWriteJSONField to configure JSON tree.

I have a table row like this:

first_name, last_name, role, catogory1, category2

Joe, Dee, undergrad, 49614,49715

How can I get a JSON data output string like below?

{

    

"data"

: {

        

"type"

"registration_sets"

,

        

"attributes"

: {

            

"registrations"

: [

                {

                    

"rule_set"

"user_rule_set"

,

                    

"first_name"

"Joe"

,

                    

"last_name"

"Dee"

,

                    

"category_labels"

: [

                        

"49614"

,

                        

"

49715

"

                    ]

                },

                {

                    

"rule_set"

"he_learner"

,

                    

"role"

"undergrad"

                }

            ]

        }

    }

}

your help will be very appreciated.

Labels (2)
3 Replies
Anonymous
Not applicable

The best way to do this will depend upon your data. This looks like a small structure where you are limited to these input columns....

 

first_name, last_name, role, category1, category2

 

....with 1 row of data. Do you need a complete and separate file for every row in the data. Is the input data limited to the columns you have shown?

 

jenn11439
Contributor
Contributor
Author

I have tDBInput query getting a dataset with columns: first_name, last_name, role, category1, category2. The each row of dataset will be iterated generating a separate JSON string to post data using tRestClient. In the JSON body, rule_set is fixed value.

The JSON structure will be like this:

{

  "data": {

    "type": "registration_sets",

    "attributes": {

      "registrations": [

        {

          "rule_set": "user_rule_set",

          "first_name": "Test10",

          "last_name": "Test10",

          "category_labels": [

            "49614",

            "49575"

          ]

        },

        {

          "rule_set": "he_learner",

          "role": "undergrad"

        }

      ]

    }

  }

}

 

How can I use tWriteJSONField or java jackson class to generate the file?

 

Thank you.

 

jenn11439
Contributor
Contributor
Author

I made it working using jackson classes.

Thank you for your help.