New: the AI firewall watches every module and explains each incident in plain words. See how it works

Data transform blocks

Reference of Change, Calculate, Scale, Template, JSON, CSV, XML, Hex, Base64 and Bytes – the blocks that reshape, compute and decode message data.

Transform blocks change the message and send it on. They are how you rename keys, compute values, build texts and decode raw device data before Save telemetry. Each has an out output and an error output. None of them keeps state.

Change

Sets, edits, deletes or moves properties of the message and of flow or global variables, in steps done from top to bottom.

SettingMeaningValues
opsThe stepsup to 16 rows

Each step:

opDoesFields
setWrites a value; missing parents are createdpath, value (any value kind)
changeReplaces every occurrence of from with to in text; non-text is left alonepath, from, to, regex (a pattern of at most 64 characters)
deleteRemoves the property or variablepath
moveCopies to the path in to, then deletes the original. The editor does not show the to field yet, so use set and delete instead.path, to
copy keysCopies every top-level key of the object at path whose whole name matches Keys matching into To objectpath, Keys matching, To object
delete keysDeletes every top-level key whose whole name matchespath, Keys matching

Paths are msg., flow. or global. paths (flow.persist:x for the persistent store). Engine fields (_…), msg.msgType and msg.originator cannot be written. Errors: invalid_value with invalid_path, read_only, invalid_key, limit (variable store full) or bad pattern; steps before the failing one are already applied.

Example: rename a device’s key before saving: step 1 set msg.payload.temperature to the path msg.payload.tmp; step 2 delete msg.payload.tmp.

Calculate

Works out an expression and writes the result.

SettingMeaningDefaultValues
exprThe expressionrequiredup to 512 characters
targetWhere the result goesmsg.payloada msg., flow. or global. path

7 / 2 is 3.5; + joins text when either side is text; arithmetic on null or any text (even "21.5") fails with type: convert with number(). Errors: invalid_value, type, div_zero, steps, limit. See Condition blocks for the functions.

Examples: round(msg.payload.temperature * 1.8 + 32, 1); 10 * log10(msg.payload.ratio); clamp(msg.payload.level, 0, 100).

Scale

Maps a number linearly from one range to another, in place.

SettingMeaningDefaultValues
propertyThe numbermsg.payloada path
in_min, in_maxThe input range0, 4095numbers, not equal
out_min, out_maxThe output range0, 100numbers
modeOutside the output rangeclampclamp (limit), wrap (wrap around), free (leave)
roundDecimal placesnone0 to 10

Formula: out_min + (value − in_min) × (out_max − out_min) / (in_max − in_min). Numeric text and true/false (1/0) count as numbers. Error invalid_value (“not a number”, or an empty input range).

Template

Builds text, or a JSON value, from {{ expression }} placeholders.

SettingMeaningDefaultValues
templateThe text{{ msg.payload }}up to 4,096 characters
targetWhere the result goesmsg.payloada msg., flow. or global. path
formattext, or json (the result is parsed as JSON)texttext, json

null becomes empty, objects and arrays are written as JSON. For JSON output, put text placeholders in quotes yourself: {"temp": {{ msg.payload }}, "unit": "{{ flow.unit }}"}. The result is at most 64 KB of text.

JSON

Turns JSON text into a value, or a value into JSON text, in place.

SettingMeaningDefaultValues
modeauto (parse text, pass the rest), parse, stringifyauto
propertyThe propertymsg.payloada path

Errors: invalid_value “not JSON: …” or “not a string”.

CSV

CSV text to records, or records to CSV text, in place.

SettingMeaningDefaultValues
modeauto, decode, encodeauto
propertyThe propertymsg.payloada path
sepField separatorcommacomma, semicolon, tab, pipe
headerDecode: the first line has the names. Encode: write a header lineoffon, off
columnsColumn names, comma-separatedemptyup to 256 characters
numbersDecode: number-like fields become numbersoffon, off
outputDecode: one message with all records (array) or one per record (rows)arrayarray, rows

Quoting follows RFC 4180. Error queue_full over 10,000 lines or records.

XML

XML text to an object, or an object to XML text.

SettingMeaningDefault
Modeparse, build, or auto
PropertyWhere the conversion happensmsg.payload
Attribute prefixPrefix of attribute keys@
Text keyKey of text next to child elements#text
Arrays / array elementsWhich elements are always arrays
NumbersNumeric text becomes numbersoff
SelectKeep only one element path, e.g. soap:Envelope/soap:Body/*/m:Price
Root, DeclarationBuilding: the root element name, the <?xml …?> line
Max bytesLargest input64 KiB (1 to 256 KiB)

A document with <!DOCTYPE is refused. At most 10,000 elements, 64 attributes per element, 128 characters per name. Errors: parse_error, dtd_refused, too_large, too_deep, bad_name, no_root.

Hex and Base64

Encode a property as hex (two lower-case digits per byte) or base64 text, or decode it back.

SettingMeaningDefaultValues
modeWhich wayautoauto, encode, decode
propertyThe propertymsg.payloada msg., flow. or global. path

In auto, text that looks like hex (or base64) is decoded and everything else encoded; short words such as test or digits such as 2024 are valid base64 or hex too, so choose encode or decode when you know the direction. Hex decoding ignores spaces and colons.

Bytes

Reads named numbers from binary data, or builds binary data from numbers.

SettingMeaningDefaultValues
modeRead or builddecodedecode, encode
fieldsOne row per fieldemptyup to 16 rows

Each field:

FieldMeaningDefaultValues
nameKey in the resultrequireda letter or _ first, up to 32 characters
offsetFirst byte, from 000 to 4,095
typeSize and kindu16u8, i8, u16, i16, u32, i32, f32
leLittle endianoff (big endian)on, off
bitsA bit range start:lengthwhole fielde.g. 0:1, 4:3
scaleDecode: × scale; encode: ÷ scale1a number

Decode reads hex text (spaces and colons ignored) or an array of byte values in msg.payload and writes { name: value }. Encode writes hex text. Error invalid_value when the data is not hex or a field lies beyond its end.

Example: a raw payload 00d7ff9c with temp (offset 0, i16, scale 0.1) and pressure (offset 2, i16) gives { "temp": 21.5, "pressure": -100 }.

Decoding raw device data

A device that sends binary data arrives with the single key raw (base64 for binary). A typical decoder in the root flow, before Save telemetry:

Switch (msg.payload.raw nempty) → Change: set msg.payload to the path msg.payload.raw
  → Base64 (decode) → Hex (encode) → Bytes (decode fields) → Save telemetry

Check the result with Test before you deploy. For LoRaWAN devices, use codecs instead; see Codecs overview. For anything the blocks cannot express, use The script block.