tRest and map JSON with tExtractJSONField with TALEND

心不动则不痛 提交于 2020-01-14 09:31:27

问题


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 :

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

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 :

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


回答1:


You have to use tMap component

And you have to configure data schema like this example :




回答2:


Select below options

Read by : JsonPath

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

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



来源:https://stackoverflow.com/questions/27641674/trest-and-map-json-with-textractjsonfield-with-talend

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!