我尝试使用Jolt库将JSON转换为另一个JSON,但没有得到所需的输出。
这是我的输入文件。
{
"maxResults": 150,
"total": 89,
"issues": [
{
"key": "1",
"fields": {
"fixVersions": [
{
"self": "FIX1-01",
"id": "11"
},
{
"self": "FIX1-02",
"id": "12"
}
]
}
},
{
"key": "2",
"fields": {
"fixVersions": [
{
"self": "FIX2-01",
"id": "21"
}
]
}
},
{
"key": "3",
"fields": {
"fixVersions": []
}
}
]
}
这是我用于转换的规范文件。
[
{
"operation": "shift",
"spec": {
"issues": {
"*": {
"key": "[&1].id",
"fields": {
"fixVersions": {
"*": {
"self": "[&1].fixVersion.name"
}
}
}
}
}
}
}
]
我得到了这个输出
[
{
"id": "1",
"fixVersion": {
"name": [
"FIX1-01",
"FIX2-01"
]
}
},
{
"fixVersion": {
"name": "FIX1-02"
},
"id": "2"
},
{
"id": "3"
}
]
这是不对的,它所做的是获取每个问题的第一个self字段值,并将其作为数组填充到输出的第一个fixVersions中,然后获取第二个self字段值,并将其填充到第二个fixVersions中,我想做的是保持输入中的结构,只需要像这样更改self字段名称。
[
{
"id": "1",
"fixVersion": [
{
"name": "FIX1-01"
},
{
"name": "FIX1-02"
}
]
},
{
"fixVersion": [
{
"name": "FIX2-01"
}
],
"id": "2"
},
{
"id": "3"
}
]
我哪里做错了?
2条答案
按热度按时间kqlmhetl1#
查看此规格是否是您正在寻找的:
输出使用它对您的输入将导致:
请注意您用于重建fixVersion(还需要考虑问题索引)列表的索引的更改,您错过了以下内容:
djp7away2#
由于您已经使用了XSLT标记和Java标记,因此可以将XSLT和/或XQuery 3与Saxon 9一起使用,并使用例如
https://xqueryfiddle.liberty-development.net/bdxZ8R