I need to convert a json(got after multiple calls and then merged it) into a specific structure.
here is my input json payload
[{
"shops": [{
"shop": {
"code": "AU5",
"streetName": "a",
"city": "a",
"district": "a",
"state": "a",
"postalCode": "a",
"country": "a"
}
}, {
"shop": {
"code": "b",
"streetName": "b",
"city": "b",
"district": "b",
"state": "b",
"postalCode": "b",
"country": "b"
}
}]
},
[
[{
"salesOffice": {
"shop": {
"code": "AU5"
},
"office": "MEL",
"branch": "MEL",
"district": "SPR",
"subRegion": "SPR",
"region": "AP"
}
}],
[{
"salesOffice": {
"shop": {
"code": "b"
},
"office": "999",
"branch": "999",
"district": "999",
"subRegion": "999",
"region": "999"
}
}
]
]]
below is the expected output json
{
"shops": [
{
"shop": {
"code": "AU5",
"streetName": "a",
"city": "a",
"district": "a",
"state": "a",
"postalCode": "a",
"country": "a",
"salesOffice": {
"office": "MEL",
"branch": "MEL",
"district": "SPR",
"subRegion": "SPR",
"region": "AP"
}
}
},
{
"shop": {
"code": "b",
"streetName": "b",
"city": "b",
"district": "b",
"state": "b",
"postalCode": "b",
"country": "b",
"salesOffice": {
"office": "999",
"branch": "999",
"district": "999",
"subRegion": "999",
"region": "999"
}
}
}
]}
while transformation, 'code' inside shop should match with 'code' inside salesOffice>>shop>>'code'
below is Json Schema for the output payload(should validate against the output)
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"shops": {
"type": "array",
"items": {
"type": "object",
"properties": {
"shop": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"streetName": {
"type": "string"
},
"city": {
"type": "string"
},
"district": {
"type": "string"
},
"state": {
"type": "string"
},
"postalCode": {
"type": "string"
},
"country": {
"type": "string"
}
},
"salesOffice": {
"type": "object",
"properties": {
"office": {
"type": "string"
},
"branch": {
"type": "string"
},
"district": {
"type": "string"
},
"subRegion": {
"type": "string"
},
"region": {
"type": "string"
}
}
},
"required": [
"code",
"streetName",
"city",
"district",
"state",
"postalCode",
"country",
"salesOffice"
]
}
},
"required": [
"shop"
]
}
}
},
"required": [
"shops"
]}
Any solution or any pointer would be a great help