解析自定义值JSON

时间:2018-10-22 10:16:31

标签: arrays json oracle parsing

我一直在使用JSON_TABLE来解析JSON有效负载,就像这样:

{
"entry": [
    {
        "changes": [
            {
                "field": "leadgen",
                "value": {
                    "ad_id": "444444444",
                    "form_id": "444444444444",
                    "leadgen_id": "444444444444",
                    "created_time": 1539170312,
                    "page_id": "444444444444",
                    "adgroup_id": "44444444444"
                }
            }
        ],
        "id": "0",
        "time": 1539170312
    }
],
"object": "page"
}

我一直在使用类似的方法来获取值:

select id,
           time,
           ad_id,       
           form_id,     
           leadgen_id,  
           created_time,
           page_id,
           adgroup_id
      from json_table (p_raw_payload  FORMAT JSON,   '$'
              COLUMNS (id             varchar2  path '$.entry.id',
                       time           number    path '$.entry.time',
                       NESTED                   path '$.entry[*]'
              COLUMNS (ad_id          varchar2  path '$.changes.value.ad_id',
                       form_id        varchar2  path '$.changes.value.form_id',
                       leadgen_id     varchar2  path '$.changes.value.leadgen_id',
                       created_time   number    path '$.changes.value.created_time',
                       page_id        varchar2  path '$.changes.value.page_id',
                       adgroup_id     varchar2  path '$.changes.value.adgroup_id')));

这很好。

我的问题是,现在我得到的JSON有效负载是“自定义”的,格式如下:

{
"created_time": "2015-02-28T08:49:14+0000",
"id": "44444444444444",
"ad_id": "44444444444444",
"form_id": "44444444444444",
"field_data": [
    {
        "name": "car_make",
        "values": [
            "Honda"
        ]
    },
    {
        "name": "full_name",
        "values": [
            "Joe Example"
        ]
    },
    {
        "name": "email",
        "values": [
            "joe@example.com"
        ]
    },
    {
        "name": "selected_dealer",
        "values": [
            "99213450"
        ]
    }
],
...
}

这意味着我实际上感兴趣的每个列名称都以值的形式出现在单独的“名称”标签中。...(“名称”:“ car_make” /“值”:“ Honda”等)。

我该如何正确解决呢?

0 个答案:

没有答案