使用 jolt 转换多个 json 对象
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输出
{
"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)即可工作的规范。
请帮忙。
谢谢,
哈里
你几乎是正确的。
这是产生预期输出的规范:
[
{
"operation": "shift",
"spec": {
"ResultSets": {
"*": {
"rows": {
"*": {
"*": "ResultSets.&3[&1].@(3,fields[&].name)"
}
}
}
}
}
}
]
解释:
&1
——指对象在数组内部的索引
- 相反,我们想将它放在相同的索引下,但由三层以上的对象包裹。这就是为什么我们使用
&3[&1]
而不是 &1
我正在尝试使用 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输出
{
"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)即可工作的规范。
请帮忙。
谢谢, 哈里
你几乎是正确的。 这是产生预期输出的规范:
[
{
"operation": "shift",
"spec": {
"ResultSets": {
"*": {
"rows": {
"*": {
"*": "ResultSets.&3[&1].@(3,fields[&].name)"
}
}
}
}
}
}
]
解释:
&1
——指对象在数组内部的索引- 相反,我们想将它放在相同的索引下,但由三层以上的对象包裹。这就是为什么我们使用
&3[&1]
而不是
&1