Which one would you use??
I wrote this post with my own views and wider explanations, but I wanted to compile here the main difference in syntax.
do
%dw 2.0
output application/json
var age = 21
---
{
person: do {
var user = "Robin"
var age = 5
---
{
name: user,
age: age
}
}
}
using
%dw 2.0
output application/json
var age = 21
---
{
person: using (user = "Robin", age = "5") {
name: user,
age: age
}
}
Besides the fact that using
is deprecated in DataWeave 2.0, I prefer to use do
way more because of the syntax. For me it is more intuitive to know where to define local functions or variables. I think you can't define named functions with using
, but you can create lambda expressions (which is a whole can of worms on its own!).
What do you think though?