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

Jolt - Get values using a list of keys, alternatives to @(2,@)

我需要创建一个 JSON 数组,以便使用 Nifi 将其拆分为多个作业。 该数组需要基于 JSON.

中的现有数组创建

无法弄清楚如何动态创建对 JSON 中另一个对象的引用。我希望引用“@(2,@)”起作用,但这不受支持。

输入

{
  "name": "Loki",
  "id": "1234",
  "loc": "Utgard",
  "age": "unknown",
  "listitems": [
    "name",
    "id"
  ]
}

规格(无效):

[
  {
    "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"
        }
      }
    }
  }
]

预期输出:

{
  "processlist" : [ 
  {
    "type" : "name",
    "value" : "Loki"
  }, {
    "type" : "id",
    "value" : "1234"
  } 
  ]
}

SPEC(运行 但不正确)

[
  {
    "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"
        }
      }
    }
  }
]

有什么想法吗?

您可以通过添加 "*" 键来进一步嵌套当前规范,同时通过 @(3,&) 动态漫游,因为此符号代表产生的键值 nameid 比如

[
  {
    "operation": "shift",
    "spec": {
      "listitems": {
        "*": {
          "*": {
            "@1": "processlist[#3].type",
            "@(3,&)": "processlist[#3].value"
          }
        }
      }
    }
  }
]