我有一个要转换的有效载荷:
输入:
{
"accounts": {
"item": [
{
"accountType": "Primary",
"accountNumber": "12345",
"accountAddresses": {
"item": [
{
"addressType": "Mailing1",
"address": {
"addressLine1": "123 main st",
"city": "New York",
"state": "NY"
}
},
{
"addressType": "Physical",
"address": {
"addressLine1": "789 Washington st",
"city": "New York",
"state": "NY"
}
}
]
}
},
{
"accountType": "Primary1",
"accountNumber": "09876",
"accountAddresses": {
"item": [
{
"addressType": "Mailing",
"address": {
"addressLine1": "123 Wall st",
"city": "New York City",
"state": "NY"
}
}
]
}
}
]
}
}
输出:
{
"accounts":[
{
"accountType":"Primary",
"accountNumber":"12345",
"accountAddresses":[
{
"addressType":"Mailing1",
"address":{
"addressLine1":"123 main st",
"city":"New York",
"state":"NY"
}
},
{
"addressType":"Physical",
"address":{
"addressLine1":"789 Washington st",
"city":"New York",
"state":"NY"
}
}
]
},
{
"accountType":"Primary1",
"accountNumber":"09876",
"addressType":"Mailing1",
"accountAddresses":[
{
"addressType":"Mailing",
"address":{
"addressLine1":"123 Wall st",
"city":"New York City",
"state":"NY"
}
}
]
}
]
}
到目前为止,我的规格是:
[
{
"operation": "shift",
"spec": {
"accounts": {
"item": {
"*": {
"accountType": "account[&1].accountType",
"accountNumber": "account[&1].accountNumber",
"accountAddresses": {
"item": {
"*": {
"addressType": "account[&1].addressType[&4]",
"address": {
"*": {
"addressLine1": "account[&1].address.addressLine1",
"city": "account[&1].address.city",
"state": "account[&1].address.state"
}
}
}
}
}
}
}
}
}
}
]
此规范不起作用。输出如下:
{
"account" : [ {
"accountType" : "Primary",
"accountNumber" : "12345",
"addressType" : [ "Mailing1", "Mailing" ]
}, {
"addressType" : [ "Physical" ],
"accountType" : "Primary1",
"accountNumber" : "09876"
} ]
}
将所有内容放在由索引分组的数组中的accountAddresses->项目中。我只想对其进行转换,以便帐户和帐户地址是数组而不是对象。
如果有人可以提供帮助,那就万分感谢。