Seperate each JSON object

Highlighted
Seven Stars

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.
 

ActiveMQ.PNG
JSON.PNG


Accepted Solutions
Seven Stars

Re: Seperate each JSON object

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

 

ReadExcelSendJSONToActiveMQ.PNG


All Replies
Nine Stars

Re: Seperate each JSON object

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:

 

json-object.png

--
Please give Kudos and mark topics as solved where appropriate.
Seven Stars

Re: Seperate each JSON object

@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.

Seven Stars

Re: Seperate each JSON object

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

 

ReadExcelSendJSONToActiveMQ.PNG

Nine Stars

Re: Seperate each JSON object

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.

--
Please give Kudos and mark topics as solved where appropriate.
Seven Stars

Re: Seperate each JSON object

@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.

Nine Stars

Re: Seperate each JSON object

@kuwaryogi27 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.

--
Please give Kudos and mark topics as solved where appropriate.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog