如何在骡子数据编织转换中添加转义字符



我想做下面的转换。我正在努力在数据编织中添加转义字符。我可以将有效负载合并为单个字符串,但无法添加转义字符。

输入

 {
   "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}}"
    }
  }

任何人都可以建议如何进行上述转换吗?蒂亚

如果我执行此数据编织,骡子已经为我添加了转义字符。[此处有效负载是您输入的 json]。我在转换之前将有效负载的 mimeType 更改为"文本/纯文本"。如果 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=" {   &quot;request&quot;:{      &quot;Id&quot;:&quot;1111&quot;,      &quot;channel&quot;:&quot;ABC&quot;,      &quot;useFilters&quot;:false   },   &quot;need&quot;:{      &quot;postcode&quot;:2222,      &quot;Imp&quot;:&quot;Mobile&quot;,      &quot;additionalProducts&quot;:[      ],      &quot;isOwner&quot;:true,      &quot;isMovingIn&quot;:true,      &quot;movingDate&quot;:&quot;2017-07-28&quot;,      &quot;otherNeeds&quot;:[         &quot;Food&quot;,         &quot;Car&quot;      ]   },   &quot;filter&quot;:{      &quot;productType&quot;:[      ],      &quot;zone&quot;:[      ],      &quot;data&quot;:[      ],      &quot;speedTier&quot;:[      ],      &quot;recommendedPlans&quot;: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>

最新更新