我在向数组添加新项目时遇到问题。 我想在地址数组中添加新项目。 任何帮助都会很感激。 提前致谢:
这是我的代码:
input.json
{
"lines": [
{
"movement": {
"source": {
"node": "Org_Node",
"address": {
"addressLine1": "abc",
"addressLine2": "def",
"addressLine3": "eg",
"addressLine4": "abc123"
},
"recipient": {
"firstName": "Ravi",
"middleName": "",
"lastName": "krishna"
},
"contactInformation": {
"mobileNo": "9687568965"
}
}
}
}
]
}
在输出中我想添加 city&状态: 预期产出是:
{
"address" : {
"address1" : "abc",
"address2" : "def",
"address3" : "eg",
"address4" : "abc123",
"city":"ATP",
"state":"AP"
},
"recipient" : {
"firstName" : "Ravi",
"middleName" : "",
"lastName" : "krishna"
},
"contactInformation" : {
"mobileNo" : "5036412733"
}
}
我写了以下规范文件以获得我想要的输出,请让我知道我必须修改的地方我是JOLT的新手。 spec.json文件:
[{
"operation": "shift",
"spec": {
"lines": {
"*": {
"movement": {
"source": {
"address": {
"addressLine*": "[#5].&1.address&(0,1)",
"*": "[#5].&1.&"
},
"recipient": {
"*": "[#5].&1.&"
},
"contactInformation": {
"*": "[#5].&1.&"
}
}
}
}
}
}
}]
答案 0 :(得分:0)
规格
[
{
"operation": "shift",
"spec": {
"lines": {
"*": {
"movement": {
"source": {
// keeping the lines array
// just keep the follow 3 fields
"address|recipient|contactInformation": "lines[&3].&"
}
}
}
}
}
},
{
"operation": "default",
"spec": {
// default has a different syntax than shift.
// You have to tell Default that lines is an array
// so that it can step into it correctly.
"lines[]": {
"*": {
"address": {
// apply cit and state defaults
// not this is not in any way data driven
// it will add these city and state defaults to everythhing
// If you need it to be data driven, you have to deal with
// that before or after Jolt
"city": "ATP",
"state": "AP"
}
}
}
}
}
]