Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 颠簸变换用键值对展平嵌套数组_Json_Jolt - Fatal编程技术网

Json 颠簸变换用键值对展平嵌套数组

Json 颠簸变换用键值对展平嵌套数组,json,jolt,Json,Jolt,我正在尝试转换以下JSON { "data": { "keyvalues": [ { "key": "location", "value": "sydney, au" }, { "key": "weather", "value": "sunny" } ] }, "food": { "name": "AllFoods", "date": "20

我正在尝试转换以下JSON

{
  "data": {
    "keyvalues": [
      {
        "key": "location",
        "value": "sydney, au"
      },
      {
        "key": "weather",
        "value": "sunny"
      }
    ]
  },
  "food": {
    "name": "AllFoods",
    "date": "2018-03-08T09:35:17-03:00",
    "count": 2,
    "food": [
      {
        "name": "chocolate",
        "date": "2018-03-08T12:59:58-03:00",
        "rating": "10",
        "data": null
      },
      {
        "name": "hot dog",
        "date": "2018-03-08T09:35:17-03:00",
        "rating": "7",
        "data": {
          "keyvalues": [
            {
              "key": "topping",
              "value": "mustard"
            },
            {
              "key": "BUN type",
              "value": "toasted"
            },
            {
              "key": "servings",
              "value": "2"
            }
          ]
        }
      }
    ]
  }
}
使用类似这样的简单方法,使用JOLT(在NIFI中)。将第一个顶级
food
属性(
name
date
count
)放入
标题
,然后将嵌套的
food
数组向上拉,然后将
food.data.keyvalues
展平到dict/hashmap中

{
  "header": {
    "location": "sydney, au",
    "weather": "sunny",
    "date": "2018-03-08",
    "count": 2
  },
  "foods": [
    {
      "name": "chocolate",
      "date": "2018-03-08T12:59:58-03:00",
      "rating": "10"
    },
    {
      "name": "hot dog",
      "date": "2018-03-08T09:35:17-03:00",
      "rating": "7",
      "topping": "mustard",
      "bun_type": "toasted",
      "servings": "2"
    }
  ]
}
我已经得到了第一个
数据
部分,但我不确定如何处理嵌套的
食物
元素。顶级
食品
信息需要移动到
标题
部分,而第二级
食品
数组需要展平
数据。keyvalues

当前规格。。。(仅处理顶部的
数据。keyvalues

规格

规格


谢谢你,米洛。我似乎还不能理解这个DSL。。。我们还需要进一步研究这个。谢谢米洛。我似乎还不能理解这个DSL。。。我们还需要进一步研究这个问题。
[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "keyvalues": {
          "*": { "@value": "@key" }
        }
      }
    }
  }
]
[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "keyvalues": {
          "*": {
            "value": "header.@(1,key)"
          }
        }
      },
      "food": {
        "date": "header.date",
        "count": "header.count",
        "food": {
          "*": {
            "name": "foods[&1].name",
            "date": "foods[&1].date",
            "rating": "foods[&1].rating",
            "data": {
              "keyvalues": {
                "*": {
                  "value": "foods[&4].@(1,key)"
                }
              }
            }
          }
        }
      }
    }
  }
]