欢迎讨论:kettle读取嵌套JSON内容的方法!

-发帖者:
-参与讨论....
【主题】:kettle读取嵌套JSON内容的方法

1.前言

最近应公司需求,需要解析多层级的嵌套json到关系型数据库中,这里大概讲解一下kettle的处理流程,具体原理其实和递归差不多,就是一层层嵌套的数据,像剥洋葱一样,一层一层的把他剥开,逐层解析。

2.实战

废话不多说。直接上图:

这是json结构:

{
    "status": "ok",
    "response": {
        "submissions": [
            {
                "id": "59434767",
                "timestamp": "2011-11-21 09:21:53",
                "user_agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0",
                "remote_addr": "192.168.1.1",
                "payment_status": "",
                "data": [
                    {
                        "field": "13776121",
                        "value": "Baylor Dallas"
                    },
                    {
                        "field": "13776401",
                        "value": "CHF"
                    },
                    {
                        "field": "13777966",
                        "value": "John Doe"
                    },
                    {
                        "field": "13780027",
                        "value": "9999"
                    },
                    {
                        "field": "13778165",
                        "value": "None of the above"
                    },
                    {
                        "field": "13778985",
                        "value": "Yes"
                    },
                    {
                        "field": "13778280",
                        "value": "Yes"
                    },
                    {
                        "field": "13778424",
                        "value": "Yes"
                    },
                    {
                        "field": "13778290",
                        "value": "Yes"
                    },
                    {
                        "field": "13778324",
                        "value": "Yes"
                    },
                    {
                        "field": "13778864",
                        "value": "Yes"
                    }
                ]
            },
            {
                "id": "59474875",
                "timestamp": "2011-11-21 17:01:22",
                "user_agent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0",
                "remote_addr": "192.168.1.1",
                "payment_status": "",
                "data": [
                    {
                        "field": "13776121",
                        "value": "Healthsouth,"
                    },
                    {
                        "field": "13776401",
                        "value": "Pneumonia"
                    },
                    {
                        "field": "13777966",
                        "value": "Jane Doe"
                    },
                    {
                        "field": "13780027",
                        "value": "390"
                    },
                    {
                        "field": "13778165",
                        "value": "Experienced a fall?"
                    },
                    {
                        "field": "13861153",
                        "value": "Yes"
                    },
                    {
                        "field": "13780018",
                        "value": "Yes"
                    },
                    {
                        "field": "13780006",
                        "value": "No"
                    },
                    {
                        "field": "13780023",
                        "value": "Yes"
                    },
                    {
                        "field": "13780024",
                        "value": "Yes"
                    }
                ]
            }
        ],
        "total": 2,
        "pages": 1
    }
}

1. 下面开始解析它,首先将第一层数据解析出来:

2. 然后,再拖一个json组件开始解析第二层级:

第二个json选取上一个json组件的输出的字段数据:然后,设置字段path

第三步:使用选择字段的值组件,来组装数据

OK。运行查看结果:this we want!!!

 

 

 发表评论     发表时间:『2020-01-08 23:50:03』


扫描二维码关注网站最新动态