我有这样的输入json 输入json 1
{
"globalRoute": [
{
"id": 527763,
"attributes": {
"arrival": {
"date": "2024-03-18T15:23:00.000Z",
"timezone": "America/New_York"
}
},
"_operation": 1
}
]
}
预期输出
{
"global_route" : {
"ship_locations" : [ {
"global_ship_location_id" : 527763,
"attributes" : {
"arrival" : {
"date" : "2024-03-18T15:23:00.000Z",
"timezone" : "America/New_York"
}
},
"_operation" : 1
} ]
}
}
我已经编写了适合此用例的震动规范。
震动规格
[
{
"operation": "shift",
"spec": {
"globalRoute": {
"*": {
"id": "global_route.ship_locations[&1].global_ship_location_id",
"attributes": {
"arrival": {
"date": "global_route.ship_locations[&3].attributes.arrival.date",
"timezone": "global_route.ship_locations[&3].attributes.arrival.timezone"
},
"departed": {
"date": "global_route.ship_locations[&3].attributes.departed.date",
"timezone": "global_route.ship_locations[&3].attributes.departed.timezone"
}
},
"_operation": "global_route.ship_locations[&1]._operation"
}
}
}
}
]
现在输入Json 2
输入json 1
{
"globalRoute": [
{
"id": 527763,
"attributes": {
"arrival": {
}
},
"_operation": 1
}
]
}
预期产出
{
"global_route" : {
"ship_locations" : [ {
"global_ship_location_id" : 527763,
"attributes" : {
"arrival" : {
}
},
"_operation" : 1
} ]
}
}
但是我当前的震动规范正在删除属性对象。如果传递的是空json,如何保持原样。 请帮助我正确的颠簸规范,以便如果我在属性中传递空 json,它应该支持,否则我们传递的数据应该被转换..
使用以下规格,希望对您有所帮助
[
{
"operation": "shift",
"spec": {
"globalRoute": {
"*": {
"id": "global_route.ship_locations[#3].global_ship_location_id",
"*": "global_route.ship_locations[#3].&"
}
}
}
}
]