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

时间:2017-11-09 00:58:51

标签: mule dataweave

我想在转型之下做。我正在努力在数据编织中添加转义字符。我能够将有效负载合并为单个字符串,但无法添加转义字符。

输入

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

1 个答案:

答案 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=" {   &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>