In jolt, how could I use an array of ids to change (or not change) the respective boolean flag fields depending on a separate respective object value?

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

In jolt, how could I use an array of ids to change (or not change) the respective boolean flag fields depending on a separate respective object value?

问题

{
"2293754_ACCESS_comment_isPresent": "true",
"6660000_ACCESS_comment_isPresent": "false"
}

英文:

Input Json:

{
  "accessIds": [
    "2293754",
    "6660000"
  ],
  "2293754_ACCESS_comment_isPresent": "false",
  "6660000_ACCESS_comment_isPresent": "false",
  "ACCESS_comment_2293754": {
    "accessId": "2293754",
    "commentIsPresent": true,
    "textValue": "No problems reported."
  }

}

Expected Output:


{
  "2293754_ACCESS_comment_isPresent": "true",
  "6660000_ACCESS_comment_isPresent": "false",
}

Here only first element of array "2293754" has "ACCESS_comment_2293754.commentIsPresent" so we change it to true.
The second element does not have this object at all. So we leave it as it is (false).

答案1

得分: 2

你可以将属性的键与对象的键进行匹配,并选择最后一个组件作为覆盖项,如果转换结果为数组,例如

[
  {
    "operation": "shift",
    "spec": {
      "*_*_*": { // 代表对象的键
        "commentI*": "&(1,3)_&(1,1)_&(1,2)_i&(0,1)"
      },
      "*_*_*_*": "&" // 代表属性
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=lastElement"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=toString" // 根据需要将布尔值转换
    }
  }
]
英文:

You can match the keys of the attributes vs. the keys of the object, and pick the last component as the overriding one, if the shift transformation resulted an array such as

[
  {
    "operation": "shift",
    "spec": {
      "*_*_*": { // represents the key of the object
        "commentI*": "&(1,3)_&(1,1)_&(1,2)_i&(0,1)"
      },
      "*_*_*_*": "&" // represents attributes
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=lastElement"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=toString" // converts from a boolean if so, as desired
    }
  }
]

huangapple
  • 本文由 发表于 2023年7月7日 05:44:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632686.html
匿名

发表评论

匿名网友

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

确定