首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jolt -使用键列表获取值,替代@(2,@)

Jolt -使用键列表获取值,替代@(2,@)
EN

Stack Overflow用户
提问于 2021-06-08 22:00:16
回答 1查看 65关注 0票数 1

我需要创建一个JSON数组,以便使用Nifi将其拆分为几个作业。该数组需要基于JSON中的现有数组创建。

我不知道如何在JSON中动态创建对另一个对象的引用。我希望引用"@(2,@)“工作,但这不受支持。

输入

代码语言:javascript
复制
{
  "name": "Loki",
  "id": "1234",
  "loc": "Utgard",
  "age": "unknown",
  "listitems": [
    "name",
    "id"
  ]
}

SPEC (这不起作用):

代码语言:javascript
复制
[
  {
    "operation": "shift",
    "spec": {
      // Loop all listitems
      "listitems": {
        "*": {
          // Get the value of the current item and push to processlist.type array
          "@": "processlist[#2].type", 
          // Here is the problem, I need to get the "top level" value for the current value/key
          "@(2,@)": "processlist[#2].value"
        }
      }
    }
  }
]

预期输出:

代码语言:javascript
复制
{
  "processlist" : [ 
  {
    "type" : "name",
    "value" : "Loki"
  }, {
    "type" : "id",
    "value" : "1234"
  } 
  ]
}

SPEC (可以运行,但不正确)

代码语言:javascript
复制
[
  {
    "operation": "shift",
    "spec": {
      // Loop all listitems
      "listitems": {
        "*": {
          // Get the value of the current item and push to processlist.type array
          "@": "processlist[#2].type", 
          // Here is the problem, I need to get the top level value for the current value/key
          // Forcing this to "name" will at least execute the code
          "@(2,name)": "processlist[#2].value"
        }
      }
    }
  }
]

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-08 23:50:59

@(3,&)动态漫游时,您可以通过添加"*"密钥进一步嵌套当前规范,因为这个&符号表示产生的密钥值nameid,例如

代码语言:javascript
复制
[
  {
    "operation": "shift",
    "spec": {
      "listitems": {
        "*": {
          "*": {
            "@1": "processlist[#3].type",
            "@(3,&)": "processlist[#3].value"
          }
        }
      }
    }
  }
]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67888557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档