首页 > 解决方案 > 如何使用 talend 将 API 数据加载到 MYSQL 数据库中

问题描述

我是 Talend 的新手。我想将我的 api(例如:www.abc.com/villages/)数据加载到我的 mysql 数据库中。我该怎么做?

这是我的 api 数据:

{
    "message": "Resource created/Updated",
    "data": {
        "items": [
            {
                "id": 256,
                "name": "Abc",
                "createdAt": "2020-07-09 04:06:23",
                "updatedAt": "2020-07-09 04:06:23"
            },
            {
                "id": 512,
                "name": "Xyz",
                "createdAt": "2020-07-09 04:06:23",
                "updatedAt": "2020-07-09 04:06:23"
            }
        ],
        "page": 1,
        "total": 51551,            
    },
    "type": null
}

标签: etltalend

解决方案


这取决于您要从 json 中提取哪些数据并加载到 MySQL 表中。
首先,您需要使用 tExtractJSONFields 组件来展平 json 数据:
在此处输入图像描述

这里我提取 id、name、createAt 和 updateAt;并将此数据记录到控制台。您可以将 tLogRow 替换为 db 输出组件。

.---+----+-------------------+-------------------.
|                   tLogRow_1                    |
|=--+----+-------------------+------------------=|
|id |name|createdAt          |updatedAt          |
|=--+----+-------------------+------------------=|
|256|Abc |2020-07-09 04:06:23|2020-07-09 04:06:23|
|512|Xyz |2020-07-09 04:06:23|2020-07-09 04:06:23|
'---+----+-------------------+-------------------'

推荐阅读