【问题标题】:Nifi Jolt Transform SpecNifi Jolt 变换规范
【发布时间】:2019-02-22 01:05:34
【问题描述】:

我正在尝试使用 nifi jolttransformjson 来转换我的 JSON。 我在玩这个网站http://jolt-demo.appspot.com/#modify-stringFunctions

我有一个 JSON

{
"response": {
"Attribute": [
  {
    "id": "670868",
    "another_id": "8385",
    "category": "A",
    "type": "abc"
  },
  {
    "id": "670870",
    "another_id": "8385",
    "category": "B",
    "type": "abc"
  }
]
}
}

我的 Jolt Spec 是

enter code here 
[
{
"operation": "shift",
"spec": {
  "response": {
    "Attribute": {
      "*": {
        "type": "TYPE",
        "category": "CATEGORY"
      }
    }
  }
}
}
]

当前输出为

{
  "TYPE" : [ "abc", "abc" ],
  "CATEGORY" : [ "A", "B" ]
}

想要的输出是

[
   {
      "TYPE":"abc",
      "CATEGORY":"A"
   },
   {
      "TYPE":"abc",
      "CATEGORY":"B"
   }
]

请帮忙。我尝试了很多组合,但我似乎无法弄清楚。

【问题讨论】:

    标签: json apache-nifi jolt


    【解决方案1】:

    查看Map to List 示例,您将找到解决方案:

    [
      {
        "operation": "shift",
        "spec": {
          "response": {
            "Attribute": {
              "*": {
                "@type": "[#2].TYPE",
                "@category": "[#2].CATEGORY"
              }
            }
          }
        }
    }
    ]
    

    【讨论】:

    • 是的,你是对的。出于某种原因,我使用了示例 6、7、11、12、13。我没有意识到它在 #5 中。非常感谢!
    【解决方案2】:
    [
      {
        "operation": "shift",
        "spec": {
          "response" : {
            "Attribute" : {
              "*" : {
                "type" : "[&1].TYPE",
                "category" : "[&1].CATEGORY"
              }
            }
          }
        }
      }
    ]
    

    【讨论】:

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