Help with dealing with Fusion JSONata
I’m probably not the only “Accidental IT” guy who now works in Fusion for a living. And for those of us “People who have liberal arts degrees who are trying to catch up with people with real degrees,” some of the newer and more code-y aspects of our job may be a little bit of a challenge. (“Work in publishing,” they said. “You’ll have a job for life,” they said...)
The thing which trips me up is that I’ll play with the JSONata exerciser and something which works perfectly fine there...doesn’t in Fusion. While Claude was trying to work with me on that, I asked it to come up with some pointers for future use. I really don’t like having AI write simple things if I can do it on my own.
So, I had it come up with this helpful one-sheet for me when it comes to working with JSONata expressions. I’m including it here in case anyone else may find it useful.
-j
WORKING WITH JSONATA IN WORKFRONT FUSION
How Fusion deviates from canonical JSONata (jsonata.org)
=========================================================
THE GOLDEN RULE: DON'T TRUST THE DISPLAY
-----------------------------------------
When you inspect incoming data in a Fusion JSONata module, what you SEE
is not always what you can REFERENCE. The module wraps and relabels data
internally. Always start with a diagnostic expression before writing your
actual logic.
STEP 1: ALWAYS DIAGNOSE FIRST
------------------------------
Before writing any expression, type just:
$
This returns everything the module is actually seeing. Use this as your
source of truth -- not the input display panel.
STEP 2: NAVIGATE FROM $[0], NOT THE KEY NAME
---------------------------------------------
In canonical JSONata, if your data looks like this:
{
"folders": [
{ "ID": "abc123", "name": "My Folder" }
]
}
You'd write folders[0].ID and it works fine in the exerciser at jsonata.org.
IN FUSION, THIS WILL RETURN NOTHING.
Fusion flattens and re-wraps the data internally. The key names shown in
the input display (like "data", "output", etc.) are Fusion's internal
labels and cannot be referenced directly in your expression.
Instead, navigate from the root using $[0]:
$[0].ID
STEP 3: RETURNING MULTIPLE FIELDS
----------------------------------
To return multiple values as an object, use explicit key/value pairs in
curly braces:
{
"ID": $[0].ID,
"name": $[0].name
}
Note: Unlike the JSONata exerciser, you MUST provide explicit key names
on the left side. Fusion will not infer them.
WATCH OUT FOR: RESERVED/SPECIAL WORDS
--------------------------------------
The word "output" appears in Fusion's input display panel but CANNOT be
used as a key reference in your expression. It is Fusion's internal label
for the result. Attempting to reference it directly will return nothing.
Other display labels like "data" may also be unreferenceable for the
same reason.
QUICK DIAGNOSTIC CHEATSHEET
----------------------------
See everything $
Get first item $[0]
Get all values (no keys) $.*
Get a specific field $[0].fieldName
Get multiple fields { "a": $[0].fieldA, "b": $[0].fieldB }