用于从嵌套列表中提取数据的 Jolt 转换
Jolt transformation for extracting data from nested list
从嵌套列表中提取数据的 Jolt 规范是什么
我一直在尝试使用 apache nifi,我想使用 joltransformation 处理器来解析 json 流文件内容,但我无法解析嵌套列表
输入JSON -
{
"posts": [
{
"network": "test",
"photos": [
{
"a": 1.7722222222222221,
"s": "https://a.com",
"m": "https://b.com",
"l": "https://ccccc.com"
}
]
},
{
"network": "test1",
"photos": [
{
"a": 1.7722222222222221,
"s": "https://d.com",
"m": "https://e.com",
"l": "https://fffff.com"
}
]
}
]
}
JOLT 转换文件 -
[
{
"operation": "shift",
"spec": {
"posts": {
"*": {
"network": "[&1].profile",
"photos": { "0": { "l": "[&1].p" } }
}
}
}
}
]
预期输出 -
[
{
"profile" : "test",
"p" : "https://ccccc.com"
},
{
"profile" : "test1",
"p" : "https://fffff.com"
}
]
实际输出 -
[
{
"profile" : "test",
"p" : [ "https://ccccc.com", "https://ffffff.com" ]
},
{
"profile" : "test1"
}
]
请帮助我,我无法弄清楚我做错了什么
你很接近
[
{
"operation": "shift",
"spec": {
"posts": {
"*": {
"network": "[&1].profile",
"photos": {
"0": {
"l": "[&3].p"
}
}
}
}
}
}
]
[&3].p
是重要的部分,因为这意味着索引是从 3 个级别向上使用的,也就是来自帖子的级别。
从嵌套列表中提取数据的 Jolt 规范是什么
我一直在尝试使用 apache nifi,我想使用 joltransformation 处理器来解析 json 流文件内容,但我无法解析嵌套列表
输入JSON -
{
"posts": [
{
"network": "test",
"photos": [
{
"a": 1.7722222222222221,
"s": "https://a.com",
"m": "https://b.com",
"l": "https://ccccc.com"
}
]
},
{
"network": "test1",
"photos": [
{
"a": 1.7722222222222221,
"s": "https://d.com",
"m": "https://e.com",
"l": "https://fffff.com"
}
]
}
]
}
JOLT 转换文件 -
[
{
"operation": "shift",
"spec": {
"posts": {
"*": {
"network": "[&1].profile",
"photos": { "0": { "l": "[&1].p" } }
}
}
}
}
]
预期输出 -
[
{
"profile" : "test",
"p" : "https://ccccc.com"
},
{
"profile" : "test1",
"p" : "https://fffff.com"
}
]
实际输出 -
[
{
"profile" : "test",
"p" : [ "https://ccccc.com", "https://ffffff.com" ]
},
{
"profile" : "test1"
}
]
请帮助我,我无法弄清楚我做错了什么
你很接近
[
{
"operation": "shift",
"spec": {
"posts": {
"*": {
"network": "[&1].profile",
"photos": {
"0": {
"l": "[&3].p"
}
}
}
}
}
}
]
[&3].p
是重要的部分,因为这意味着索引是从 3 个级别向上使用的,也就是来自帖子的级别。