【问题标题】:Jolt transformation for extracting data from nested list用于从嵌套列表中提取数据的 Jolt 转换
【发布时间】:2019-02-04 17:13:23
【问题描述】:

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

我一直在用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"
 }
]

请帮助我,我无法弄清楚我做错了什么

【问题讨论】:

    标签: json apache-nifi jolt


    【解决方案1】:

    你很亲密

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

    [&3].p 是重要部分,因为这意味着索引是从 3 级以上使用的,即来自帖子的那个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 1970-01-01
      • 2023-02-05
      • 1970-01-01
      • 2017-12-31
      • 2022-01-05
      相关资源
      最近更新 更多