[英]Transforming multiple json objects using jolt
我正在尝试使用 jolt 转换此 json 输入。 请帮助我的规格有什么问题。
JSON 输入
{
"ResultSets": {
"ClassPaths": {
"currentRow": 0,
"fields": [
{
"name": "path"
},
{
"name": "loadOrder"
}
],
"rows": [
[
"/a/b/genenerator.jar",
"-10"
],
[
"/a/b/server.jar",
"0"
]
]
},
"DisabledComponents": {
"currentRow": 0,
"fields": [
{
"name": "name"
},
{
"name": "location"
}
],
"rows": [
[
"ActiveDirectoryLdapComponent",
"/a/b/component.hda"
],
[
"AppAdapterCore",
"/a/b/AdapterCore.hda"
]
]
}
}
}
预期 JSON Output
{
"ResultSets" : {
"ClassPaths" : [ {
"path" : "/a/b/genenerator.jar",
"loadOrder" : "-10"
}, {
"path" : "/a/b/server.jar",
"loadOrder" : "0"
} ],
"DisabledComponents" : [ {
"name" : "ActiveDirectoryLdapComponent",
"location" : "/a/b/component.hda"
}, {
"name" : "AppAdapterCore",
"location" : "/a/b/AdapterCore.hda"
} ]
}
}
我的规格是
[
{
"operation": "shift",
"spec": {
"ResultSets": {
"*": {
"rows": {
"*": {
"*": "ResultSets.&1.@(3,fields[&].name)"
}
}
}
}
}
}
]
如果我将 * 替换为密钥名称(ClassPath 或 DisabledComponents),它可以工作,但只提供 json 与该密钥。
我无法对密钥进行硬编码,因为它是动态的,而且我们事先也不知道那里有什么。
所以我想要一个在规范中不指定确切键(ClassPath 或 DisabledComponents)的规范。
请帮忙。
谢谢,哈里
你几乎是正确的。 这是产生预期 output 的规范:
[
{
"operation": "shift",
"spec": {
"ResultSets": {
"*": {
"rows": {
"*": {
"*": "ResultSets.&3[&1].@(3,fields[&].name)"
}
}
}
}
}
}
]
解释:
&1
- 指数组内 object 的索引&3[&1]
而不是&1
1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.