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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Bharath12
Contributor III
Contributor III

how to convert delimited values to json array and key value pair

Hi All,

 

I have issues with converting delimited values  to JSON array. can some one help me with the below requirements.

 

Requirement 1:

 

source from mysql DB:

id

123,456,7458,4566897,32132164

 

I need JSON output like below.

 

"ID":["123","456","7458","4566897","32132164"]

 

Requirement 2: 

source data

work email                                                 Alias

12345@gmail.com                        xyz@gmail.com,abc@gmail.com,cyd@gmail.com

 

i need output like below

 

"email" : [ {"type" : "workemail", "value" : "12345@gmail.com" }, {"type" : "alias", "value" : "xyz@gmail.com" }, {"type" : "alias", "value" : "abc@gmail.com" }, {"type" : "alias", "value" : "cyd@gmail.com" }].

 

Can some one help me with the above seniors. Appreciate your help.

 

Thanks, 

 

 

 

 

 

 

Labels (4)
1 Solution

Accepted Solutions
Bharath12
Contributor III
Contributor III
Author

Thanks @uganesh . Could you please help me solution for the below example as well.

 

Requirement 1:

 

source from mysql DB:

id

123,456,7458,4566897,32132164

 

I need JSON output like below.

 

"ID":["123","456","7458","4566897","32132164"]

 

Thanks,

View solution in original post

11 Replies
Anonymous
Not applicable

Hi,

 

   Could you please advise these two requirements as columns from same input data set or should we consider these two requirements independently?

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

Bharath12
Contributor III
Contributor III
Author

Hi Nikhil,

 

both columns from same input data set.

 

Thanks,

Ram 

Anonymous
Not applicable

Anonymous
Not applicable

@rchinta 

 

I tried something quick but unfortunately it didn't work out. We can do parsing through routine mode but I am travelling this week and do not have sufficient time to check it 😞

 

@uganesh  or @DataTeam  may be interested in this one.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

akumar2301
Specialist II
Specialist II

Thanks Nikhil.
2nd one Looks like nested json array. I will check this.
I think need to reformat the input to prepare json.
Anonymous
Not applicable

@uganesh 

 

Yeah Abhi... I was thinking to do tnormalize and then process... I am in between travel and could not think much on this one.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

DataTeam1
Creator
Creator

@rchinta  are you sure you want to get this?:

"email" : [ {"type" : "workemail", "value" : "12345@gmail.com" }, {"type" : "alias", "value" : "xyz@gmail.com" }, {"type" : "alias", "value" : "abc@gmail.com" }, {"type" : "alias", "value" : "cyd@gmail.com" }]

 

I can show you how to get this:

"email": [
{
"work_email": "12345@gmail.com",
"Alias": "[\"xyz@gmail.com\",\"abc@gmail.com\",\"cyd@gmail.com\"]"
}
]

 

Here is the solution:

First you have to normalize Alias column then use tWriteJSONField

 

0683p000009M3Tx.jpg

 

then send it to tFileOutputJSON

 

0683p000009M3Pw.jpg

 

 

 

akumar2301
Specialist II
Specialist II

my Idea is to first reformat the input

input example

12345@gmail.com;abc@gmail.com,def@gmail.com

12346@gmail.com;abc@gmail.com,def@gmail.com

formatted data

0683p000009M3U7.jpg

 

Then Parse it with tWriteJsonFields

 

0683p000009M3TA.jpg

 

My Job

0683p000009M3UC.jpg

 

Output

 

{"email":
[{"type":"workmail","value":"12345@gmail.com"},
{"type":"alias","value":"abc@gmail.com"},
{"type":"alias","value":"def@gmail.com"}]
}
{"email":[{"type":"workmail","value":"12346@gmail.com"},
{"type":"alias","value":"abc@gmail.com"},
{"type":"alias","value":"def@gmail.com"}
]}

 

similar approach can be done for Requirement 1. refer attached job.


jsonparsertest_0.1.zip
Bharath12
Contributor III
Contributor III
Author

Thanks @uganesh . Could you please help me solution for the below example as well.

 

Requirement 1:

 

source from mysql DB:

id

123,456,7458,4566897,32132164

 

I need JSON output like below.

 

"ID":["123","456","7458","4566897","32132164"]

 

Thanks,