Java 无法使用JOLT解析器获得预期的输出
我有以下意见: 我需要的预期输出如下:Java 无法使用JOLT解析器获得预期的输出,java,jolt,Java,Jolt,我有以下意见: 我需要的预期输出如下: [{ "ownerId": "XTV7I728", "vehicleId": "999", "engines":{ "engineId": "1", "engineName": "Standard Engine", "engineHp": 300 } }, { "ownerId": "XTV7I728", "vehicleId": "99
[{
"ownerId": "XTV7I728",
"vehicleId": "999",
"engines":{
"engineId": "1",
"engineName": "Standard Engine",
"engineHp": 300
}
},
{
"ownerId": "XTV7I728",
"vehicleId": "999",
"engines":{
"engineId": "2",
"engineName": "Custom Engine",
"engineHp": 450
}
}]
我尝试了以下规格,但它抛出了一个错误:
[{
"ownerId": "ownerId",
"*": {
"vehicleId": "vehicleId",
"engineId": "engineId",
"engineHp": "engineHp"
}
}]
错误:
请告诉我哪里出了问题。如果使用链规范,然后使用规范部分执行对象树的实际遍历,则必须指定操作。这应该起作用:
[
{
"operation": "shift",
"spec": {
"*": {
"engines": {
"*": {
"@(2,ownerId)": "[#2].ownerId",
"@(2,vehicleId)": "[#2].vehicleId",
"*": "[#2].&"
}
}
}
}
}
]
谢谢你的帮助。明天早上让我试试。另外,因为我是这个解析器的新手,所以仍然对一些概念感到非常困惑。你能解释一下规格,特别是发动机零件吗。这实际上会有所帮助。你可以看到我无法设计这样的规格,我修改了我的输出。你能帮我纠正一下输出吗?我知道@travers向后遍历并获取该级别的键并返回值,但我没有得到最后一行*:[2]。&以及为什么ownerId和VehicleId被分组在@tag中?我还理解一件事,如果我从RHS中删除,它将创建一个值数组
Error running the Transform.
JOLT Chainr 'operation' must implement Transform or ContextualTransform at index:0.
[
{
"operation": "shift",
"spec": {
"*": {
"engines": {
"*": {
"@(2,ownerId)": "[#2].ownerId",
"@(2,vehicleId)": "[#2].vehicleId",
"*": "[#2].&"
}
}
}
}
}
]