英文:
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
>      }
>    }
>  }
>]
>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论