2017-11-09 16 views
0

以下の変換をしたい。私はデータ織りでエスケープ文字を追加しようとしています。ペイロードを単一の文字列にマージできますが、エスケープ文字は追加できません。エスケープ文字をノーデータ織り変換に追加する方法

入力

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

このデータウェーブを実行すると、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> 
関連する問題