我正在尝试转换一个在子元素中有数组元素的json。我想把它转换成所有json元素中都有父属性的父元素的json数组
我的输入json
{
"Transmission": {
"TransmissionGUID": "transId1",
"Employer": [
{
"EmployerPartyID": "employerId1",
"Employee": [
{
"EmployeeGenderCode": "M",
"MaritalStatusCode": "Married"
},
{
"EmployeeGenderCode": "F",
"MaritalStatusCode": "UnMarried"
}
]
},
{
"EmployerPartyID": "employerId2",
"Employee": [
{
"EmployeeGenderCode": "M2",
"MaritalStatusCode": "Married2"
},
{
"EmployeeGenderCode": "F2",
"MaritalStatusCode": "UnMarried"
}
]
}
]
}
}
字符串
我想把它变成
[
{
"Transmission": {
"TransmissionGUID": "transId1",
"Employer": [
{
"EmployerPartyID": "employerId1",
"Employee": [
{
"EmployeeGenderCode": "M",
"MaritalStatusCode": "Married"
}
]
}
]
}
},
{
"Transmission": {
"TransmissionGUID": "transId1",
"Employer": [
{
"EmployerPartyID": "employerId1",
"Employee": [
{
"EmployeeGenderCode": "F",
"MaritalStatusCode": "UnMarried"
}
]
}
]
}
},
{
"Transmission": {
"TransmissionGUID": "transId1",
"Employer": [
{
"EmployerPartyID": "employerId2",
"Employee": [
{
"EmployeeGenderCode": "M2",
"MaritalStatusCode": "Married2"
}
]
}
]
}
},
{
"Transmission": {
"TransmissionGUID": "transId1",
"Employer": [
{
"EmployerPartyID": "employerId",
"Employee": [
{
"EmployeeGenderCode": "F2",
"MaritalStatusCode": "UnMarried2"
}
]
}
]
}
}
]
型
我试着写了如下的转换的震动规格
[
{
"operation": "shift",
"spec": {
"Transmission": {
"Employer": {
"*": {
"Employee": {
"*": {
"@(4,TransmissionGUID)": "[].Transmission.TransmissionGUID",
"@(2,EmployerPartyID)": "[].Transmission.Employer[].EmployerPartyID",
"@": "[].Transmission.Employer[].Employee[]"
}
}
}
}
}
}
}
]
型
但是它没有给出想要的输出。有人能帮我吗?
1条答案
按热度按时间jfewjypa1#
我不认为你可以用一个移位规范来完成这个转换。我可以用两个移位来完成,第一个移位将父子信息分组在唯一键下。唯一键是使用父\子数组中的子索引和父索引的组合创建的。例如,第一个雇主(索引0)有两个孩子,所以如果你用下划线(_)连接父索引和子索引,在中间你会得到一个唯一的键为每个父孩子为0_0 & 0_1.对于第二雇主的孩子它将1_0 & 1_1等等.一旦你已经分组每个父孩子在其唯一的键,第二个移位转换将基本上抓住每个父孩子和转储它在一个数组没有唯一的键,这应该给给予你需要的结果.
字符串