apache-nifi - Jolt - 使用键列表获取值,@(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,&)
动态漫游,因为这个&符号表示产生的键值name
,id
例如
[
{
"operation": "shift",
"spec": {
"listitems": {
"*": {
"*": {
"@1": "processlist[#3].type",
"@(3,&)": "processlist[#3].value"
}
}
}
}
}
]
推荐阅读
- css - 仅当我们在模态内容之外单击时才关闭覆盖
- python - 如何在 python gpgme 中使用高级(低级)函数来删除一个键?
- mysql - 删除重复项后如何求和
- mysql - 如何设置具有复合主键的外键?
- spring - 使用 @Valid 和 Thymeleaf 验证 spring-boot 中的输入
- sql - PosgreSQL 语法转换为雪花 - Group by Clause 问题
- git - 如何删除要求凭据的 github 登录弹出窗口?
- asp.net - 在 ASP.NET Web 窗体中使用 OpenId Connect 时的身份验证 Cookie 超时
- python - 如果其中一个值为空,Python 会继续打印。csv字典
- java - 访问同一包的另一个类中的嵌套类