英文:
Unable to get expected output using JOLT parser
问题
我有以下input
:
[
{
"ownerId": "XTV7I728",
"vehicleId": "999",
"engines": [
{
"engineId": "1",
"engineName": "Standard Engine",
"engineHp": 300
},
{
"engineId": "2",
"engineName": "Custom Engine",
"engineHp": 450
}
]
}
]
我需要如下的expected
输出:
[{
"ownerId": "XTV7I728",
"vehicleId": "999",
"engines": {
"engineId": "1",
"engineName": "Standard Engine",
"engineHp": 300
}
},
{
"ownerId": "XTV7I728",
"vehicleId": "999",
"engines": {
"engineId": "2",
"engineName": "Custom Engine",
"engineHp": 450
}
}]
我尝试了以下的spec
但是报错了:
[{
"ownerId": "ownerId",
"*": {
"vehicleId": "vehicleId",
"engineId": "engineId",
"engineHp": "engineHp"
}
}]
错误信息:
运行转换时出错。
JOLT Chainr 'operation' 必须在索引0处实现Transform或ContextualTransform。
请告诉我我哪里做错了。
英文:
I have below input
:
[
{
"ownerId": "XTV7I728",
"vehicleId": "999",
"engines": [
{
"engineId": "1",
"engineName": "Standard Engine",
"engineHp": 300
},
{
"engineId": "2",
"engineName": "Custom Engine",
"engineHp": 450
}
]
}
]
I need the expected
output as below:
[{
"ownerId": "XTV7I728",
"vehicleId": "999",
"engines":{
"engineId": "1",
"engineName": "Standard Engine",
"engineHp": 300
}
},
{
"ownerId": "XTV7I728",
"vehicleId": "999",
"engines":{
"engineId": "2",
"engineName": "Custom Engine",
"engineHp": 450
}
}]
I tried below spec
but it throws an error:
[{
"ownerId": "ownerId",
"*": {
"vehicleId": "vehicleId",
"engineId": "engineId",
"engineHp": "engineHp"
}
}]
Error
:
Error running the Transform.
JOLT Chainr 'operation' must implement Transform or ContextualTransform at index:0.
Please let me know where I went wrong.
答案1
得分: 1
您需要指定操作(如果使用 Chain spec),然后是一个执行实际“遍历”对象树的 `spec` 部分。应该像这样工作:
[
{
"operation": "shift",
"spec": {
"*": {
"engines": {
"*": {
"@(2,ownerId)": "[#2].ownerId",
"@(2,vehicleId)": "[#2].vehicleId",
"*": "[#2].&"
}
}
}
}
}
]
英文:
You have to specify the operation (if using a Chain spec) and then a spec
section that does the actual "walking" of your object tree. This should work:
[
{
"operation": "shift",
"spec": {
"*": {
"engines": {
"*": {
"@(2,ownerId)": "[#2].ownerId",
"@(2,vehicleId)": "[#2].vehicleId",
"*": "[#2].&"
}
}
}
}
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论