【问题标题】:How do we traverse a jolt spec?我们如何遍历 jolt 规范?
【发布时间】:2021-11-02 05:49:04
【问题描述】:

这是一个简单的问题,我是 nifi 和 jolt 的新手。我只是想知道,如何在使用通配符的同时遍历 jolt 规范。例如,这是 jolt 演示站点中的示例,

输入是

{
  "data": {
    "1234": {
      "clientId": "12",
      "hidden": true
    },
    "1235": {
      "clientId": "35",
      "hidden": false
    }
  }
}

规格是

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "*": {
          "hidden": {
            "true": {
              // if hidden is true, then write the value disabled to the RHS output path
              // Also @(3,clientId) means lookup the tree 3 levels, to the "1234" or "1235" level,
              //  and then come back down down the tree and grabe the value of "clientId"
              "#disabled": "clients.@(3,clientId)"
            },
            "false": {
              "#enabled": "clients.@(3,clientId)"
            }
          }
        }
      }
    }
  }
]

输出是

{
  "clients" : {
    "12" : "disabled",
    "35" : "enabled"
  }
}

我们是如何得到上述输出的?就像@(3,clientsid)一样。据我了解,它上升了3个级别。但是关于什么..规范或输入的3个级别?无论哪种方式,如何向上移动3个级别,您能在这里定义哪些级别吗?

提前致谢

【问题讨论】:

    标签: json apache-nifi jolt


    【解决方案1】:

    只需向后计算每个左花括号({)或冒号(:)的数量。只要它们不是独立的,例如:{,则将其计为只有一个,以便在这种情况下到达"*" 通配符在"data" 键下的目标键,并且对于@(3,clientId);第一级是在"#disabled""#enabled" 旁边穿过冒号(:),第二级是在每个布尔键旁边穿过打开的花括号,然后第三级是在后面穿过打开的花括号"hidden" 键以使用 "data" 键访问对象的索引。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-12
      • 2022-12-22
      • 2023-04-11
      • 1970-01-01
      相关资源
      最近更新 更多