Reputation: 103
I'm doing json to xml in dataweave and for this m using variable, this is my below json
{"step1": [
"lightratio": {
"step1Name": "mystep"
},
"lightratio": {
"step1Name":"mystep"
}
]
}
my dataweave script
%dw 1.0
%output application/xml
%var test = step1.lightratio.step1Name
---
{
my logic
}
Myquery:- I want to assigned the value of json element "step1Name" i.e "mystep" to dataweave variable i.e "test" ( onlye value) , how can I achieve this , it is fine for me if i put only value which is position at zero in json array.
Upvotes: 0
Views: 1213
Reputation: 324
You can use skipNullOn
for situations when payload is null.
%dw 1.0
%output application/xml skipNullOn="everywhere"
%var payload = {
"step1":[
{
"lightratio":{
"step1Name":"mystep"
}
},
{
"lightratio":{
"step1Name":"mystep"
}
}
]
}
%var test = payload.step1[0].lightratio.step1Name
---
root : {
varValue: test
}
Output with payload
<?xml version='1.0' encoding='windows-1252'?>
<root>
<varValue>mystep</varValue>
</root>
Output with null payload
<?xml version='1.0' encoding='windows-1252'?>
<root/>
Upvotes: 0
Reputation: 2694
i assume the json from your question is the payload. you access step1Name
from the first element in the step1
list like this:
payload.step1[0].lightratio.step1Name
Upvotes: 1