[英]Replace value in Json in Dataweave
The mule payload is in flowVars (infodata) ule子的有效载荷在flowVars中(infodata)
[
{
"status": "submitted",
"identity": "",
"papers": {
"code1": "12csd3cbsdj",
"code2": "skd02nd28dn",
"date": "2016-06-22",
"party": {
"due_date": "2016-06-22",
"personel": {
"email": "tt@test.com",
"value": {
"amount": "0.10",
"inflation": "HIGH"
}
}
}
}
}
]
Inside Dataweave, (1) how to remove the square brackets? 在Dataweave里面,(1)如何删除方括号? (2) how to replace the value of amount and inflation dynamically (from flowVars)?
(2)如何动态替换金额和通货膨胀值(来自flowVars)?
Question 2:You can directly use flowVars inside dataweave or if the values are in url you can dynamically set values using inboundProperties
. 问题2:您可以在dataweave中直接使用flowVars,或者如果值在url中,则可以使用
inboundProperties
动态设置值。 Refer: https://docs.mulesoft.com/mule-user-guide/v/3.7/dataweave-reference-documentation 请参阅: https : //docs.mulesoft.com/mule-user-guide/v/3.7/dataweave-reference-documentation
I have used set variable where you can dynamically exact it.Test Url used in this flow: http://localhost:8083/test?inflation=HIGH 我在可以动态精确化的位置使用了set变量。在此流程中使用了测试网址: http:// localhost:8083 / test?inflation = HIGH
<flow name="testFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP">
</http:listener>
<logger level="INFO" doc:name="Logger"/>
<set-variable variableName="dynamicValueAmount" value="#['2']" doc:name="Variable"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
[
{
"status": "submitted",
"identity": "",
"papers": {
"party": {
"due_date": "2016-06-22",
"personel": {
"email": "tt@test.com",
"value": {
"amount": flowVars.dynamicValueAmount,
"inflation": inboundProperties.'http.query.params'.inflation
}}}}}
]]]></dw:set-payload>
</dw:transform-message>
<object-to-string-transformer doc:name="Object to String"/>
<set-payload value="#[ message.payload =org.mule.util.StringUtils.replace(message.payload,"[","{");message.payload =org.mule.util.StringUtils.replace(message.payload,"]","}")]" doc:name="Set Payload"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
Regarding Question one, i have externally used replace function in set Payload( Working fine - other way). 关于问题一,我在设置有效负载中使用了外部替换功能(工作正常-其他方式)。 I believe it can be achieve in standard way by using Dataweave itself.
我相信可以通过使用Dataweave本身以标准方式实现。 Let wait for the answers.
让我们等待答案。
I have resolved question #1 我已经解决了问题1
%dw 1.0
%output application/java
---
{
data:flowVars.infodata replace /(\[|\])/ with ""
}
I'm still trying to understand how to dynamically change the content of the payload for question #2. 我仍在尝试了解如何动态更改问题2的有效负载的内容。
flowVars.infodata map {}
or just get the first object data: flowVars.infodata[0]
. flowVars.infodata map {}
或仅获取第一个对象data: flowVars.infodata[0]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.