JSON 通过 Dataweave 进行转换
JSON transformation via Dataweave
我有一个输入 JSON,我想将其转换为另一个 JSON 结构:
输入JSON
{
data={
schema=81Ze2hDYGKOQYW02LVtUMQ,
payload={
value__c=500,
reference__c=00001503PM,
CreatedById=0051x000003SQ9eAAG,
originalReference__c=882595596510490G,
currency__c=SEK,
CreatedDate=2020-09-10T15:16:57.175Z,
merchantAccount__c=Hastens_eCom_Test
},
event={replayId=18188}
},
channel=/event/Capturepayment__e
}
我想把它转换成下面的格式。
输出JSON
{
"originalReference": "882595596510490G",
"modificationAmount": {
"value": 500,
"currency": "SEK"
},
"reference": "00001503PM",
"merchantAccount": "Hastens_eCom_Test"
}
您的输入负载似乎不是有效的 JSON。
使用调整为有效的输入负载 JSON:
{
"data":{
"schema":"81Ze2hDYGKOQYW02LVtUMQ",
"payload":{
"value__c":500,
"reference__c":"00001503PM",
"CreatedById":"0051x000003SQ9eAAG",
"originalReference__c":"882595596510490G",
"currency__c":"SEK",
"CreatedDate":"2020-09-10T15:16:57.175Z",
"merchantAccount__c":"Hastens_eCom_Test"
},
"event":{
"replayId":"18188"
}
},
"channel":"/event/Capturepayment__e"
}
以下数据编织表达式:
%dw 2.0
output application/json
---
{
originalReference: payload.data.payload.originalReference__c,
modificationAmount: {
value: payload.data.payload.value__c,
currency: payload.data.payload.currency__c,
},
reference: payload.data.payload.reference__c,
merchantAccount: payload.data.payload.merchantAccount__c
}
将产生预期的输出:
{
"originalReference": "882595596510490G",
"modificationAmount": {
"value": 500,
"currency": "SEK"
},
"reference": "00001503PM",
"merchantAccount": "Hastens_eCom_Test"
}
下面的 dwl 将产生预期的输出
%dw 2.3
output application/json
---
{
originalReference: payload.data.payload.originalReference__c,
modificationAmount: {
value: payload.data.payload.value__c,
currency: payload.data.payload.currency__c,
},
reference: payload.data.payload.reference__c,
merchantAccount: payload.data.payload.merchantAccount__c
}
我有一个输入 JSON,我想将其转换为另一个 JSON 结构:
输入JSON
{
data={
schema=81Ze2hDYGKOQYW02LVtUMQ,
payload={
value__c=500,
reference__c=00001503PM,
CreatedById=0051x000003SQ9eAAG,
originalReference__c=882595596510490G,
currency__c=SEK,
CreatedDate=2020-09-10T15:16:57.175Z,
merchantAccount__c=Hastens_eCom_Test
},
event={replayId=18188}
},
channel=/event/Capturepayment__e
}
我想把它转换成下面的格式。
输出JSON
{
"originalReference": "882595596510490G",
"modificationAmount": {
"value": 500,
"currency": "SEK"
},
"reference": "00001503PM",
"merchantAccount": "Hastens_eCom_Test"
}
您的输入负载似乎不是有效的 JSON。
使用调整为有效的输入负载 JSON:
{
"data":{
"schema":"81Ze2hDYGKOQYW02LVtUMQ",
"payload":{
"value__c":500,
"reference__c":"00001503PM",
"CreatedById":"0051x000003SQ9eAAG",
"originalReference__c":"882595596510490G",
"currency__c":"SEK",
"CreatedDate":"2020-09-10T15:16:57.175Z",
"merchantAccount__c":"Hastens_eCom_Test"
},
"event":{
"replayId":"18188"
}
},
"channel":"/event/Capturepayment__e"
}
以下数据编织表达式:
%dw 2.0
output application/json
---
{
originalReference: payload.data.payload.originalReference__c,
modificationAmount: {
value: payload.data.payload.value__c,
currency: payload.data.payload.currency__c,
},
reference: payload.data.payload.reference__c,
merchantAccount: payload.data.payload.merchantAccount__c
}
将产生预期的输出:
{
"originalReference": "882595596510490G",
"modificationAmount": {
"value": 500,
"currency": "SEK"
},
"reference": "00001503PM",
"merchantAccount": "Hastens_eCom_Test"
}
下面的 dwl 将产生预期的输出
%dw 2.3
output application/json
---
{
originalReference: payload.data.payload.originalReference__c,
modificationAmount: {
value: payload.data.payload.value__c,
currency: payload.data.payload.currency__c,
},
reference: payload.data.payload.reference__c,
merchantAccount: payload.data.payload.merchantAccount__c
}