我想在转型之下做。我正在努力在数据编织中添加转义字符。我能够将有效负载合并为单个字符串,但无法添加转义字符。
输入
{
"request":{
"Id":"1111",
"channel":"ABC",
"useFilters":false
},
"need":{
"postcode":2222,
"Imp":"Mobile",
"additionalProducts":[
],
"isOwner":true,
"isMovingIn":true,
"movingDate":"2017-07-28",
"otherNeeds":[
"Food",
"Car"
]
},
"filter":{
"productType":[
],
"zone":[
],
"data":[
],
"speedTier":[
],
"recommendedPlans":true
}
}
输出
{
"needs": {
"key": "capture_value",
"value": "{\"request\":{\"Id\":\"1111\",\"channel\":\"ABC\",\"useFilters\":false},\"need\":{\"postcode\":2222,\"Imp\":\"Mobile\",\"additionalProducts\":[],\"isOwner\":true,\"isMovingIn\":true,\"movingDate\":\"2017-07-28\",\"otherNeeds\":[\"Food\",\"Car\"]},\"filter\":{\"productType\":[],\"zone\":[],\"data\":[],\"speedTier\":[],\"recommendedPlans\":true}}"
}
}
任何人都可以建议如何进行上述转换? TIA
答案 0 :(得分:0)
如果我执行此数据编织,mule已经为我添加了转义字符。 [此处有效负载是您输入的json]。我将有效负载的mimeType更改为" text / plain"在转型之前。如果mimeType是" application / json",则不会添加转义字符。
%dw 1.0
%output application/json
---
{
needs : {
key : "capture_value",
value : payload
}
}
我的完整流程:
<flow name="pocFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<set-payload value=" { "request":{ "Id":"1111", "channel":"ABC", "useFilters":false }, "need":{ "postcode":2222, "Imp":"Mobile", "additionalProducts":[ ], "isOwner":true, "isMovingIn":true, "movingDate":"2017-07-28", "otherNeeds":[ "Food", "Car" ] }, "filter":{ "productType":[ ], "zone":[ ], "data":[ ], "speedTier":[ ], "recommendedPlans":true }}" mimeType="text/plain" doc:name="Set Payload"/>
<dw:transform-message metadata:id="5a45debe-d080-4024-9d24-e0ccf07ce1b4" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
needs : {
key : "capture_value",
value : payload
}
}]]></dw:set-payload>
</dw:transform-message>
</flow>
</mule>