颠簸转换,用于从嵌套列表中提取数据

时间:2019-02-04 17:13:24

标签: json apache-nifi jolt

从嵌套列表中提取数据的Jolt规范是什么

我一直在尝试apache nifi,我想使用joltransformation处理器来解析json流文件内容,但是我无法解析嵌套列表

输入JSON-

{
"posts": [
 {
   "network": "test",
   "photos": [
     {
       "a": 1.7722222222222221,
       "s": "https://a.com",
       "m": "https://b.com",
       "l": "https://ccccc.com"
     }
   ]
 },
 {
   "network": "test1",
   "photos": [
     {
       "a": 1.7722222222222221,
       "s": "https://d.com",
       "m": "https://e.com",
       "l": "https://fffff.com"
     }
   ]
 }
]
}

JOLT转换文件-

[
{
 "operation": "shift",
 "spec": {
   "posts": {
     "*": {
       "network": "[&1].profile",
       "photos": { "0": { "l": "[&1].p" } }
     }
   }
 }
}
]

预期输出-

[ 
 {
 "profile" : "test",
 "p" : "https://ccccc.com"
 }, 
 {
 "profile" : "test1",
 "p" : "https://fffff.com"
 }
]

实际输出-

[ 
 {
 "profile" : "test",
 "p" : [ "https://ccccc.com", "https://ffffff.com" ]
 }, 
 {
 "profile" : "test1"
 }
]

请帮助我,我无法弄清楚自己在做什么错

1 个答案:

答案 0 :(得分:0)

你很亲密

[
  {
    "operation": "shift",
    "spec": {
      "posts": {
        "*": {
          "network": "[&1].profile",
          "photos": { 
            "0": { 
              "l": "[&3].p" 
             } 
           }
        }
      }
    }
  }
]

[&3].p是重要的部分,因为这意味着从3个级别开始使用索引,这是帖子中的一个级别。