Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
kuwaryogi27
Creator
Creator

Seperate each JSON object

I have a use case where we read an excel using java code since the schema is not fixed.
and create a JSON out of it and the JSON that is getting created is attached in the TEST.json file.
In this file, I want to separate out the content [ ] from each map
In a globalmap, we have multiple HashMaps and we need to get the JSON's row by row so that it can be sent to ActiveMQ.
 

0683p000009M6HM.png
0683p000009M6I9.png

Labels (3)
1 Solution

Accepted Solutions
kuwaryogi27
Creator
Creator
Author

Attached is the job screenshot to achieve this task.
Regards,
Yogesh.

 

0683p000009M6Iz.png

View solution in original post

6 Replies
nfz11
Creator III
Creator III

Use a tExtractJSONFields component.  The key part is configuring the loop query so you may want to learn about JSONPath or XPath.  Here is the input and output from a test job:

 

Starting job TestSeparateJsonObject at 00:42 11/07/2019.

[statistics] connecting to socket on port 3995
[statistics] connected
.--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.
|                                                                                    #1. tLogRow_1                                                                                     |
+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| key  | value                                                                                                                                                                         |
+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| json | {"returnMap1": {"content":[{"id":1111111,"label":"Testing","languageCode":"en_US"}]},"returnMap2": {"content":[{"id":2222222,"label":"New Testing","languageCode":"en_GB"}]}} |
+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

.------------------------.
|     #1. tLogRow_2      |
+--------------+---------+
| key          | value   |
+--------------+---------+
| id           | 1111111 |
| label        | Testing |
| languageCode | en_US   |
+--------------+---------+

.----------------------------.
|       #2. tLogRow_2        |
+--------------+-------------+
| key          | value       |
+--------------+-------------+
| id           | 2222222     |
| label        | New Testing |
| languageCode | en_GB       |
+--------------+-------------+

[statistics] disconnected

Job TestSeparateJsonObject ended at 00:42 11/07/2019. [exit code=0]

Here is a screenshot of the test job showing the details of the tExtractJSONFields component where I use JSONPath in the loop query:

 

0683p000009M6Id.png

kuwaryogi27
Creator
Creator
Author

@nfz11 , the JSON I attached was a sample one the real JSON is a bit complex I tried tWriteJsonFileds but it was not suitable for the current scenario. So the best way to achieve this was making separate JSON files and reading it through tFileList --> tFileInputRaw --> tJavaRow (read the message and send it to next component as string) --> tMomOutput.

As of now, the task has been solved. Thank you for the guidance and really appreciate it.

kuwaryogi27
Creator
Creator
Author

Attached is the job screenshot to achieve this task.
Regards,
Yogesh.

 

0683p000009M6Iz.png

nfz11
Creator III
Creator III

That is good that you solved it, but next time be clearer about what you are asking about and give relevant sample input in text format.  People are going to try to help you and if you give meaningless sample data and ask the question in an unclear manner it wastes their time.

kuwaryogi27
Creator
Creator
Author

@nfz11, my bad, I am really sorry for this mistake will never ever let this happen again. 
Thank you for your valuable time.
Apologies,
Yogesh.

nfz11
Creator III
Creator III

@ykasture thank you for your apology.  You are not the only one who does it, believe me, I see it more often than not.  Good luck in your Talend work.