简体   繁体   English

使用 Jolt 对键进行 JSON 到 JSON 转换

[英]JSON to JSON transformation on keys using Jolt

Jolt newbie here!在这里震动新手! I would like to transform a JSON input from this template:我想从此模板转换 JSON 输入:

[
  {
    "canalId": "",
    "startDate": "",
    "typeCanal": "",
    "origin": "",
    "principal": false,
    "ligne1": "",
    "ligne2": "",
    "ligne4": "",
    "ligne6": ""
  },
  {
    ...
  }
]

to the same template, only with some keys changing names:到同一个模板,只有一些键改变了名称:

[
  {
    "id_canal": "",
    "startDate": "",
    "media": "",
    "origin": "",
    "principal": false,
    "adrL1": "",
    "adrL2": "",
    "adrL3": "",
    "adrL4": ""
  },
  {
    ...
  }
]

So far, I managed to either use this spec:到目前为止,我设法要么使用这个规范:

[
    {
      "operation": "shift",
      "spec": {
        "*": {
          "canalId": "&1.id_canal",
          "typeCanal": "&1.media",
          //More if needed
          "*": "&1.&"
        }
      }
    }
  ]

But it returns me some indexes that I don't need, plus I would like to keep the fact that it is a Json Array, aka the square brackets.但是它返回了一些我不需要的索引,而且我想保留它是一个 Json 数组的事实,也就是方括号。

Or this one but it requires a split on the incoming JSON to deal only with parts of it:或者这个,但它需要对传入的 JSON 进行拆分以仅处理其中的一部分:

[
  {
    "operation": "shift",
    "spec": {
      "canalId": "id_canal",
      "typeCanal": "media",
      // More if needed
      "*": "&"
    }
  }
]

But in that case, I would like it to become a JSON array and not just a JSON object.但在那种情况下,我希望它成为一个 JSON 数组,而不仅仅是一个 JSON 对象。

I am using all of this in a Camel route as it is the requirement, is there any Spec I could use that would do the trick?我在 Camel 路线中使用了所有这些,因为这是要求,有没有我可以使用的规范可以做到这一点? Or maybe another idea based on Camel itself?或者也许是基于骆驼本身的另一个想法?

Thanks in advance!提前致谢!

Adding an extra shift following yours would do the trick:在你的后面添加一个额外的班次就可以了:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "canalId": "&1.id_canal",
        "typeCanal": "&1.media",
        //More if needed
        "*": "&1.&"
      }
    }
    },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].&"
      }
    }
    }
  ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM