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