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

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Divide JSON into blocks when key's value changes

Hi there,

 

I receive JSON files having thousands of lines and I want to divide it into 'n' blocks having the same key.

 

For instance let's say I have the following input data:

 

[{key:A, key2=abc}; {key:A, key2=abe},
{key:B, key2=zyw}, {key:B, key2=123},
{key:C, key2=fgh}]

I want to split the above into 3 blocks: A, B, C

 

I've tried using tFlowToIterate but I can't find the Talend's way to split on a condition and then process the end of the job for each split...

 

Could someone indicate a way? Thx!

 

 

 

Labels (2)
1 Reply
rmartin2
Creator II
Creator II

Hi,

 

Since, I think, your key is random, you can't use XPath to extract blocks.

Given that, you should split your JSON into 5 lines like this :

{key:A, key2=abc}

 using a tNormalize components on the JSON String.

Then you extract, and "tag" your line with the key and use a tAggregateRow to build a List.

 

Using .toString() method on the list will output all data, separated by a comma. Feel free to adapt the mechanism.

 

Sincerely