我正在尝试将JSON映射到另一个应用程序,该应用程序期望以自己的格式接收数据。我正在使用AWS Lambda,当事件被触发时,会获取以下JSON,需要根据应用程序的期望进行解析和映射。但是关键堆栈非常大,例如在“细节”中的“ratePlan”中的“rateCode”,有近20000个费率代码,如“abc”,“xyz”等。这不是一个很好的映射方式。
if "rateCode" == "abc":
application_two_dict["rate_code"] = 123
因此,有许多键具有大量的值。 最好的映射方式是什么?还需要以两种方式进行,例如当我们从应用程序2获得数据时,我们需要解析JSON并映射密钥,以便应用程序1可以理解,反之亦然。
{
"customer": {
"firstName": "john",
"lastName": "doe",
"email": "john.doe@test.com",
"mailingAddress": {
"address1": "123 N 1st st",
"address2": "789",
"countryCode": "USA",
"stateCode": "AZ",
"city": "Phoenix",
"postalCode": "34567"
},
"telephoneNumber": {
"telephoneNumber": "1235456789"
}
},
"paymentAccount": {
"firstName": "john",
"lastName": "doe",
"paymentAccountType": "VA",
"expirationDate": "2021-05-31",
"billingAddress": {
"address1": "1234 N 1st st",
"address2": "435",
"city": "Phoenix",
"countryCode": "USA",
"postalCode": "213445",
"stateCode": "AZ"
}
},
"Details": {
"123": [{
"quantity": 1,
"ratePlan": {
"rateCode": "abc",
"DetailsList": [{
"CategoryCode": "1234",
}]
}
}
}
我仍然没有app2的json精确格式
示例json
例如
app1的json
{
"Details": {
"123": [{
"quantity": 1,
"ratePlan": {
"rateCode": "abc",
"DetailsList": [{
"CategoryCode": "1234",
}]
}
}
}
}
app 2 json
{
user_details_code : 123,
quantity : [1],
rate_plan : {
rate_code: "xyz",
category_code : "US_SAN"
}
}