【发布时间】:2021-05-25 10:30:58
【问题描述】:
我想使用 JOLT 转换来做两件事:
- 过滤名为 myarray 的数组中的元素,以便只保留具有“v_518”属性的元素
- 过滤掉除“v_518”和“lfdn”之外的其余元素的所有属性
输入:
{
"isError": false,
"isValid": true,
"myarray": [
{
"p_0001": "1",
"p_0002": "1",
"p_0003": "1",
"p_0004": "1",
"v_518": "0,214506186",
"lfdn": 89709
},
{
"p_0001": "2",
"p_0002": "1",
"p_0003": "1",
"v_518": "0,3823236",
"lfdn": 89710
},
{
"p_0001": "3",
"p_0002": "1",
"p_0003": "1",
"lfdn": 89711
}
],
"errorMessage": null,
"exceptionMessage": null,
"innerExceptionMessage": null
}
期望的输出:
{
"isError": false,
"isValid": true,
"myarray": [
{
"v_518": "0,214506186",
"lfdn": 89709
},
{
"v_518": "0,3823236",
"lfdn": 89710
}
],
"errorMessage": null,
"exceptionMessage": null,
"innerExceptionMessage": null
}
到目前为止我尝试过的,但没有按预期工作:
[
{
"operation": "shift",
"spec": {
"isError": "isError",
"isValid": "isValid",
"myarray": {
// loop thru all the elements in value array
"*": {
"v_518": {
// if the value "v_518" exists
// grab the whole object and write it out to
// a v_518_array array.
"@(1,v_518)": "v_518_array",
"@(1,lfdn)": "v_518_array"
}
}
},
"errorMessage": "errorMessage",
"exceptionMessage": "exceptionMessage",
"innerExceptionMessage": "innerExceptionMessage"
}
}
]
我尝试使用 http://jolt-demo.appspot.com/#andrewkcarter2 中的示例,但我不知道该怎么做。
【问题讨论】:
标签: json etl apache-nifi jolt