将Json字段”LVL2″重命名为”ORG_LVL_1″在JOLT中。

huangapple go评论55阅读模式
英文:

Rename Json field "LVL2" to "ORG_LVL_1" in JOLT

问题

[
  {
    "ORG_LVL_2": "Co0053",
    "status": "Active"
  },
  {
    "ORG_LVL_2": "Co0054",
    "status": "Active"
  }
]
英文:

Rename Json field "LVL2" to "ORG_LVL_1" in JOLT

[
  {
    "LVL2": "Co0053",
    "status": "Active"
  },
  {
    "LVL2": "Co0054",
    "status": "Active"
  }
]

Desired Output where ORG_LVL_2 is the modified/renamed JSON field which was previously LVL2 :

[
  {
    "ORG_LVL_2": "Co0053",
    "status": "Active"
  },
  {
    "ORG_LVL_2": "Co0054",
    "status": "Active"
  }
]

答案1

得分: 1

你可以使用以下的转换规则之一:

[
  { // 生成新的属性,即"ORG_LVL_2"
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "ORG_LVL_2": "@(1,LVL2)"
      }
    }
  },
  { // 删除原始属性
    "operation": "remove",
    "spec": {
      "*": {
        "LVL2": ""
      }
    }
  }  
]

或者

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*2": "[&1].ORG_(0,1)_2", // 使用&(0,1)表示技术来复制子串LVL;其中0表示当前级别,1表示第一个星号(实际上只有一个星号)
        "*": "[&1].&" // 保持其他属性不变
      }
    }
  }
]
英文:

You can use either of the following transformation specs :

>json
>[
> { // generate new attribute, namely "ORG_LVL_2"
> "operation": "modify-overwrite-beta",
> "spec": {
> "*": {
> "ORG_LVL_2": "@(1,LVL2)"
> }
> }
> },
> { // delete the original attribute
> "operation": "remove",
> "spec": {
> "*": {
> "LVL2": ""
> }
> }
> }
>]
>

or

>json
>[
> {
> "operation": "shift",
> "spec": {
> "*": {
> "*2": "[&1].ORG_&(0,1)_2", // use &(0,1) representation technique >to replicate the substring LVL; where 0 : the current level, 1 : the first >asterisk(indeed there's only single one)
> "*": "[&1].&" // keep the other attribute fixed
> }
> }
> }
>]
>

huangapple
  • 本文由 发表于 2023年6月1日 04:47:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76377163.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定