5

I'm quite new to Talend and I am stuck with getting JSON data using tRest.

We Suppose that I am trying to get all posts from social networks.

That's why I am using https://tagboard.com to get data which is formatted in JSON.

Here is one of the scenarios I tried. I have an output JSON data like this from https://post-cache.tagboard.com/search/tunisie?count=2 with 2 posts as example, I removed some nodes to clarify ... :

{
"posts": 
 [
    {
        "network": "twitter",
        "post_id": "547835328170823680",
        "text": "#tunisie .. #tunis",
        "html": " ",
        "permalink": " ",
        "post_time": 1419449095,
        "user_id": "159415522",
        "user_name": " ",
        "user_real_name": " ",
        "user_profile_image_url": " ",
        "hashtags": [ "tunisie", "tunis" ]        
    },
    {
        "network": "Facebook",
        "post_id": "547835328170823680",
        "text": "#tunisia .. #tunis",
        "html": " ",
        "permalink": " ",
        "post_time": 1777449095,
        "user_id": "159995522",
        "user_name": " ",
        "user_real_name": " ",
        "user_profile_image_url": " ",
        "hashtags": [ "tunisia", "tunis2" ]        
    }
]
}

Here's the first Talend job :

enter image description here

And I configured tExtractJSONField to extract text field from the data as below :

enter image description here

enter image description here

In fact, I need these fields : newtork, text, post_time, and the list of hashtags.

Because of Body on the Mapping table, I think I can not add more attributes to map the rest of fields.

I found there's a way to map data with tXMLMap where the body field can be extended to add more fields :

enter image description here

I believe there's a way do the same thing for JSON but I dont know how and I wait for your help.

Ali Ben Messaoud
  • 11,690
  • 8
  • 54
  • 87

2 Answers2

2

You have to use tMap component enter image description here

And you have to configure data schema like this example :

enter image description here

Ali Ben Messaoud
  • 11,690
  • 8
  • 54
  • 87
  • You should've made a specific answer to his question. Not just pasted some example. It's hard to follow what you're talking about here as the fields don't match up. – Sean Gildea May 25 '17 at 14:41
0

Select below options

Read by : JsonPath

Loop json query : "$.posts[*]"

Extract inner json array fields using [0].network and [1].network in tExtractJSONFields component.

Community
  • 1
  • 1