我有 JSON 输入,我想从中将数组的相同子元素提取到一个字段中。尝试弄清楚如何使用 NiFi JSLTTransformJSON 处理器构建 JSLT。
输入:
{
"name": "John Smith",
"ID": "123123123",
"address": [
{
"location": "123 Main, Citty, ST",
"info": {
"type": "single family",
"own": "yes"
}
},
{
"location": "123 Lane, Wonderland, ST",
"info": {
"type": "apartment",
"own": "yes"
}
},
{
"location": "123 Street, Place, ST",
"info": {
"type": "condo",
"own": "no"
}
}
]
}
所需输出:
{
"name": "John Smith",
"ID": "123123123",
"residence_type": "single family, apartment, condo"
}
所需输出,其中
info.own == "yes"
:
{
"name": "John Smith",
"ID": "123123123",
"residence_type": "123 Main, Citty, ST; 123 Lane, Wonderland, ST"
}
我不知道可能有多少个地址。
对于第一个所需的输出:
{
"residence_type":join([for (.address) .info.type],", "),
"address":null,
*:.
}
对于第二个所需的输出:
{
"residence_type":join([for (.address) .location if(.info.own=="yes")],", "),
"address":null,
*:.
}
如果您尝试根据 info.own 值组合两者:
{
"residence_type":join([for (.address) .location if(.info.own=="yes")]+[for (.address) .info.type if(.info.own!="yes")] ,"; "),
"address":null,
*:.
}
希望有帮助。