I have an MQTT route set up for Sparrow to send information to a Broker. Sparrow publishes two different shapes of data for air.qo and motion.qo. I know that I can set up two different routes and use two different JSONata formaters for each set of data. However, my preference would be to have a SINGLE route and change the formatter based on the source of the data, e.g.:
IF air.qo then
{
“sensor”: $substring($split(file,“#”)[0],16,8),
“humidity”:body.humidity,
“pressure”:body.pressure,
“temperature”:9/5*body.temperature+32,
“voltage”:body.voltage
}
ELSE if motion.qo then
{
“sensor”: $substring($split(file,“#”)[0],16,8),
“created_at”: $fromMillis(when*1000),
“motion_count”: body.count,
“motion_total”: body.total
}
Is this possible with JSONata? @RobLauer ?
I tried this but got a syntax error:
{
$split(file,“#”)[1] = “motion.qo” ?
{
“sensor”: $substring($split(file,“#”)[0],16,8),
“created_at”: $fromMillis(when1000),
“motion_count”: body.count,
“motion_total”: body.total
}
:
{
“sensor”: $substring($split(file,“#”)[0],16,8),
“humidity”:body.humidity,
“pressure”:body.pressure,
“temperature”:9/5body.temperature+32,
“voltage”:body.voltage
}
}