如何将值从上对象移动到下对象并在颠簸转换中保持分组
How to move values from upper to lower object and keep grouping in jolt transformation
我正在尝试从大型 json 文件中提取数据。我需要在提取数据时匹配来自嵌套对象和列表的数据。
我为此编写了数十个规范。最接近的 'wrong' 解决方案使输出充满空值。目前的规范非常接近,但它在列表中留下了一些数据,我需要以不同的方式分布。它使用两个班次。
[
{
"Contents": [
{
"original": "<h4>Hour 1</h4>",
"type": "other"
},
{
"content": {
"artist": "01art1816-01",
"catalog_no": "cat1816-01",
"comp_work": "comp1816-01",
"organ": "org1816-01"
},
"original": "1816-01",
"type": "listing"
},
{
"content": {
"artist": "art1816-02",
"catalog_no": "1816-02",
"comp_work": "1816-02",
"organ": "1816-02"
},
"original": "1816-02",
"type": "listing"
}
],
"filepath": "/listings/2018/1816/index.html",
"program_number": "1816"
},
{
"Contents": [
{
"original": "<h4>Hour 1</h4>",
"type": "other"
},
{
"content": {
"artist": "02art1839-01",
"catalog_no": "1839-01",
"comp_work": "1839-01",
"organ": "1839-01"
},
"original": "1839-01",
"type": "listing"
},
{
"original": "origin-othr",
"type": "other"
}
],
"filepath": "/listings/2018/1839/index.html",
"program_number": "1839"
},
{
"Contents": [
{
"original": "<h4>Part 1</h4>",
"type": "other"
},
{
"content": {
"artist": "03art8843-01",
"catalog_no": "8843-01",
"comp_work": "8843-01",
"organ": "8843-01"
},
"original": "8843-01",
"type": "listing"
},
{
"content": {
"artist": "art8843-02",
"catalog_no": "8843-02",
"comp_work": "8843-02",
"organ": "8843-02"
},
"original": "8843-02",
"type": "listing"
}
],
"filepath": "/listings/1988/8843/index.html",
"program_number": "8843"
}
]
我需要 'program_number' 和 'filepath' 在内容下的每个对象中。
预计:
{
"playlist": [{
"show": "1816",
"path": "/listings/2018/1816/index.html",
"artist": "artist1816-01",
"catalog_no": "cat1816-01",
"comp_work": "comp1816-01",
"organ": "org1816-01"
}, {
"show": "1816",
"path": "/listings/2018/1816/index.html",
"artist": "artist1816-02",
"catalog_no": "cat1816-02",
"comp_work": "comp1816-02",
"organ": "org1816-02"
}, {
"show": "1839",
"path": "/listings/2018/1839/index.html",
"artist": "artist1839-01",
"catalog_no": "cat1839-01",
"comp_work": "comp1839-01",
"organ": "org1839-01"
}, {
"show": "8843",
"path": "/listings/1988/8843/index.html",
"artist": "artist8843-01",
"catalog_no": "cat8843-01",
"comp_work": "comp8843-01",
"organ": "org8843-01"
}, {
"show": "8843",
"path": "/listings/1988/8843/index.html",
"artist": "artist8843-02",
"catalog_no": "cat8843-02",
"comp_work": "comp8843-02",
"organ": "org8843-02"
}]
}
实际:
{
"playlist": [{
"show": "1816",
"path": "/listings/2018/1816/index.html",
"artist": ["artist1816-01", "artist1816-02"],
"catalog_no": ["cat1816-01", "cat1816-02"],
"comp_work": ["comp1816-01", "comp1816-02"],
"organ": ["org1816-01", "org1816-02"]
}, {
"show": "1839",
"path": "/listings/2018/1839/index.html",
"artist": "artist1839-01",
"catalog_no": "cat1839-01",
"comp_work": "comp1839-01",
"organ": "org1839-01"
}, {
"show": "8843",
"path": "/listings/1988/8843/index.html",
"artist": ["artist8843-01", "artist8843-02"],
"catalog_no": ["cat8843-01", "cat8843-02"],
"comp_work": ["comp8843-01", "comp8843-02"],
"organ": ["org8843-01", "org8843-02"]
}]
}
使用此规范:
[
{
"operation": "shift",
"spec": {
"*": {
"program_number": "playlist.[&1].show",
"filepath": "playlist.[&1].path",
"Contents": {
"*": {
"type": {
"listing": {
"@(2,content)": "playlist.[&5]"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"playlist": {
"*": {
"*": {
"artist": "playlist[&2].artist",
"catalog_no": "playlist[&2].catalog_no",
"comp_work": "playlist[&2].comp_work",
"organ": "playlist[&2].organ",
"@show": "playlist[&2].show",
"@path": "playlist[&2].path"
}
}
}
}
}
]
稍作修改后:
班次如下:
- 将文件路径和program_number复制到数组
- 按列表类型过滤
- 格式
[
{
"operation": "shift",
"spec": {
"*": {
"Contents": {
"*": {
"@": "[&3].[&1]",
"@(2,filepath)": "[&3].[&1].path",
"@(2,program_number)": "[&3].[&1].show"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"type": {
"listing": {
"@(2)": "[]"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"show": "playlist.[&1].&",
"path": "playlist.[&1].&",
"content": {
"*": {
"@": "playlist.[&3].&"
}
}
}
}
}
]
我正在尝试从大型 json 文件中提取数据。我需要在提取数据时匹配来自嵌套对象和列表的数据。
我为此编写了数十个规范。最接近的 'wrong' 解决方案使输出充满空值。目前的规范非常接近,但它在列表中留下了一些数据,我需要以不同的方式分布。它使用两个班次。
[
{
"Contents": [
{
"original": "<h4>Hour 1</h4>",
"type": "other"
},
{
"content": {
"artist": "01art1816-01",
"catalog_no": "cat1816-01",
"comp_work": "comp1816-01",
"organ": "org1816-01"
},
"original": "1816-01",
"type": "listing"
},
{
"content": {
"artist": "art1816-02",
"catalog_no": "1816-02",
"comp_work": "1816-02",
"organ": "1816-02"
},
"original": "1816-02",
"type": "listing"
}
],
"filepath": "/listings/2018/1816/index.html",
"program_number": "1816"
},
{
"Contents": [
{
"original": "<h4>Hour 1</h4>",
"type": "other"
},
{
"content": {
"artist": "02art1839-01",
"catalog_no": "1839-01",
"comp_work": "1839-01",
"organ": "1839-01"
},
"original": "1839-01",
"type": "listing"
},
{
"original": "origin-othr",
"type": "other"
}
],
"filepath": "/listings/2018/1839/index.html",
"program_number": "1839"
},
{
"Contents": [
{
"original": "<h4>Part 1</h4>",
"type": "other"
},
{
"content": {
"artist": "03art8843-01",
"catalog_no": "8843-01",
"comp_work": "8843-01",
"organ": "8843-01"
},
"original": "8843-01",
"type": "listing"
},
{
"content": {
"artist": "art8843-02",
"catalog_no": "8843-02",
"comp_work": "8843-02",
"organ": "8843-02"
},
"original": "8843-02",
"type": "listing"
}
],
"filepath": "/listings/1988/8843/index.html",
"program_number": "8843"
}
]
我需要 'program_number' 和 'filepath' 在内容下的每个对象中。
预计:
{
"playlist": [{
"show": "1816",
"path": "/listings/2018/1816/index.html",
"artist": "artist1816-01",
"catalog_no": "cat1816-01",
"comp_work": "comp1816-01",
"organ": "org1816-01"
}, {
"show": "1816",
"path": "/listings/2018/1816/index.html",
"artist": "artist1816-02",
"catalog_no": "cat1816-02",
"comp_work": "comp1816-02",
"organ": "org1816-02"
}, {
"show": "1839",
"path": "/listings/2018/1839/index.html",
"artist": "artist1839-01",
"catalog_no": "cat1839-01",
"comp_work": "comp1839-01",
"organ": "org1839-01"
}, {
"show": "8843",
"path": "/listings/1988/8843/index.html",
"artist": "artist8843-01",
"catalog_no": "cat8843-01",
"comp_work": "comp8843-01",
"organ": "org8843-01"
}, {
"show": "8843",
"path": "/listings/1988/8843/index.html",
"artist": "artist8843-02",
"catalog_no": "cat8843-02",
"comp_work": "comp8843-02",
"organ": "org8843-02"
}]
}
实际:
{
"playlist": [{
"show": "1816",
"path": "/listings/2018/1816/index.html",
"artist": ["artist1816-01", "artist1816-02"],
"catalog_no": ["cat1816-01", "cat1816-02"],
"comp_work": ["comp1816-01", "comp1816-02"],
"organ": ["org1816-01", "org1816-02"]
}, {
"show": "1839",
"path": "/listings/2018/1839/index.html",
"artist": "artist1839-01",
"catalog_no": "cat1839-01",
"comp_work": "comp1839-01",
"organ": "org1839-01"
}, {
"show": "8843",
"path": "/listings/1988/8843/index.html",
"artist": ["artist8843-01", "artist8843-02"],
"catalog_no": ["cat8843-01", "cat8843-02"],
"comp_work": ["comp8843-01", "comp8843-02"],
"organ": ["org8843-01", "org8843-02"]
}]
}
使用此规范:
[
{
"operation": "shift",
"spec": {
"*": {
"program_number": "playlist.[&1].show",
"filepath": "playlist.[&1].path",
"Contents": {
"*": {
"type": {
"listing": {
"@(2,content)": "playlist.[&5]"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"playlist": {
"*": {
"*": {
"artist": "playlist[&2].artist",
"catalog_no": "playlist[&2].catalog_no",
"comp_work": "playlist[&2].comp_work",
"organ": "playlist[&2].organ",
"@show": "playlist[&2].show",
"@path": "playlist[&2].path"
}
}
}
}
}
]
稍作修改后:
班次如下:
- 将文件路径和program_number复制到数组
- 按列表类型过滤
- 格式
[
{
"operation": "shift",
"spec": {
"*": {
"Contents": {
"*": {
"@": "[&3].[&1]",
"@(2,filepath)": "[&3].[&1].path",
"@(2,program_number)": "[&3].[&1].show"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"type": {
"listing": {
"@(2)": "[]"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"show": "playlist.[&1].&",
"path": "playlist.[&1].&",
"content": {
"*": {
"@": "playlist.[&3].&"
}
}
}
}
}
]