# JSONata exception -- JSONata expression help please

**URL:** <https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658>\
**Category:** General\
**Tags:** jsonata, change-node\
**Created:** [12 November 2025 17:18 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658 "2025-11-12T17:18:56Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubnemo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dubnemo/32/38759_2.png) [@dubnemo](https://discourse.nodered.org/u/dubnemo)\
**Post date:** [12 November 2025 17:18 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/1 "2025-11-12T17:18:56Z")

</div>

I am at a loss why this JSONata is failing with the following error:'  
Expected "}", got ":"

I am trying to prepare the JSON payload for a QuickBase API call:

> **[Quickbase API Portal](https://developer.quickbase.com/operation/upsert)**
>
> Quickbase Developer Documentation

This is not how I would have shaped this JSON but it is the 'contract'. I would not have used the value property but instead had a literal. The numbered properties relate to a field in a QuickBase table.

Note that flow.shipmentContents is an array of shipment lines:

```auto
{
   "to": "bvhw2455g",
   "data": [
       $map(
            flow.shipmentContents,
            function($v) {
               "8": {"value": $v.SALES_ORDER_ID & '-' $v.DOCUMENT_TYPE & '-' & $v.LINE_ID},
               "9": {"value": $v.LINE_TYPE},
               "11": {"value": $v.GTIN},
               "12": {"value": $v.ITEM_DESCRIPTION},
               "13": {"value": $v.ALT_DESCRIPTION},
               "14": {"value": $v.DESCRIPTION},
               "15": {"value": $v.QUANTITY_ORDERED - $v.QUANTITY_SHIPPED},
               "16": {"value": $v.QUANTITY_ORDERED},
               "22": {"value": flow.foreignKeyId}
            }
        )
    ],
   "fieldsToReturn": [
        1,
        2
    ]
}

```

Google Gemini suggested wrapping the inner mapped object with (), as well as the concatenation but that does not help:

```auto
{
   "to": "bvhw2455g",
   "data": [
       $map(
            flow.shipmentContents,
            function($v) {(
               "8": {"value": ($v.SALES_ORDER_ID & '-' $v.DOCUMENT_TYPE & '-' & $v.LINE_ID)},
               "9": {"value": $v.LINE_TYPE},
               "11": {"value": $v.GTIN},
               "12": {"value": $v.ITEM_DESCRIPTION},
               "13": {"value": $v.ALT_DESCRIPTION},
               "14": {"value": $v.DESCRIPTION},
               "15": {"value": $v.QUANTITY_ORDERED - $v.QUANTITY_SHIPPED},
               "16": {"value": $v.QUANTITY_ORDERED},
               "22": {"value": flow.foreignKeyId}
            )}
        )
    ],
   "fieldsToReturn": [
        1,
        2
    ]
}

```

Thoughts?  
Please don't tell me to use JavaScript instead.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 November 2025 17:36 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/2 "2025-11-12T17:36:18Z")

</div>

I added code blocks around your code to make the post readable.

> [@dubnemo](#):
>
> Please don't tell me to use JavaScript instead.

This kind of statement always puzzles me.

- There are over 13 million JS developers around the world (various articles)
- By my crude reckoning (and some research), there are ~10k JSONata devs
- JS is faster (often a by a magnitude) than JSONata, especially in larger payloads and array processing.
- Node-RED has first class JS type checking, syntax help and support in the Monaco editor (JSONata support is a hand full of completions and syntax colourisation, shoe-horned in to the editor by me)
- LLMS have far more knowledge of JS than JSONata

* * *

Anyhow, back to your question, I wish I could help, but I am not up to speed on JSONata (I use JS for anything more than simple strings or numbers) and the docs / examples / LLMs are not great either.

There are one or 2 JSONata wizards in the forum, I'm certain someone can assist.

Maybe try tweaking the title to entice them in (e.g. "Need help with JSONata expression" might work?)

  

EDIT

I also moved this to the #General category (#Developing Nodes is for developeing contrib nodes)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [12 November 2025 17:43 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/3 "2025-11-12T17:43:27Z")

</div>

I asked chatgpt and it offered  
.

GPT-OSS 120B

**What’s wrong**

1. **Missing commas** between the key/value pairs inside the object that the `$map` callback returns.
2. **String‑concatenation syntax** is wrong – you can’t mix `&` with a literal `-` without quoting the dash.
3. The `$map` call must return an **array of objects** , so each object literal needs to be wrapped in `{ … }`.
4. In JSONata the **object keys must be quoted** when they are not simple identifiers (e.g., `"8"`).

* * *

## Fixed JSONata expression

jsonata

```auto
{
  "to": "bvhw2455g",
  "data": $map(
    flow.shipmentContents,
    function($v) {
      {
        "8": {"value": $v.SALES_ORDER_ID & "-" & $v.DOCUMENT_TYPE & "-" & $v.LINE_ID},
        "9": {"value": $v.LINE_TYPE},
        "11": {"value": $v.GTIN},
        "12": {"value": $v.ITEM_DESCRIPTION},
        "13": {"value": $v.ALT_DESCRIPTION},
        "14": {"value": $v.DESCRIPTION},
        "15": {"value": $v.QUANTITY_ORDERED - $v.QUANTITY_SHIPPED},
        "16": {"value": $v.QUANTITY_ORDERED},
        "22": {"value": flow.foreignKeyId}
      }
    }
  ),
  "fieldsToReturn": [1, 2]
}

```

I have no idea if that's any better, I'd have probably done it with javascript. 🙃

---

<div class="post-metadata">

**Author:** ![dubnemo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dubnemo/32/38759_2.png) [@dubnemo](https://discourse.nodered.org/u/dubnemo)\
**Post date:** [12 November 2025 17:43 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/4 "2025-11-12T17:43:37Z")

</div>

Hi Steve, thanks for that reply. Google Gemini did make this statement when I fed it the URL to this post.

> A known issue exists with the JSONata parser implementation in Node-RED's `Change` node regarding multi-line object definitions within function bodies when an outer object wraps the entire expression. The recommended solution from the Node-RED community is to define the JSONata expression to return only the array directly, handling surrounding keys like `"to"` , `"data"` , and `"fieldsToReturn"` in a preceding template/function node or within the Node-RED flow structure itself.

I tried the template approach, but even this gave the same error. I suspect the value property is causing the parser to not parse.

```auto
[
   $map(
       flow.shipmentContents,
       function($v) {
           (
               "8": {
                   "value": (
                       $v.SALES_ORDER_ID & '-' $v.DOCUMENT_TYPE & '-' &
               $v.LINE_ID
                   )
           },
               "9": {"value": $v.LINE_TYPE},
               "11": {"value": $v.GTIN},
               "12": {"value": $v.ITEM_DESCRIPTION},
               "13": {"value": $v.ALT_DESCRIPTION},
               "14": {"value": $v.DESCRIPTION},
               "15": {
                   "value": (
                       $v.QUANTITY_ORDERED - $v.QUANTITY_SHIPPED
                   )
           },
               "16": {"value": $v.QUANTITY_ORDERED},
               "22": {"value": flow.foreignKeyId}
   )
       }
        )
    ]

```

ADMIN EDIT: Wrapped code in triple back ticks for readability and to prevent forum formatting messing it up

---

<div class="post-metadata">

**Author:** ![dubnemo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dubnemo/32/38759_2.png) [@dubnemo](https://discourse.nodered.org/u/dubnemo)\
**Post date:** [12 November 2025 17:44 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/5 "2025-11-12T17:44:23Z")

</div>

That means Javascript is probably next. 🤣

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [12 November 2025 18:09 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/6 "2025-11-12T18:09:19Z")

</div>

> [@dubnemo](#):
>
> ```auto
> function($v) {
> (
> "8": {
> "value": (
> $v.SALES_ORDER_ID & '-' $v.DOCUMENT_TYPE & '-' &
> $v.LINE_ID
> )
> },
> 
> ```

That isn't a object defintion, the fix from @jbudd is:

> [@jbudd](#):
>
> ```auto
> flow.shipmentContents,
> function($v) {
> {
> "8": {"value":
> 
> ```

i.e. the second '{' is the object definition, the first '{' is the function definition and then you'll have to add a return - it being a function:

```auto
flow.shipmentContents,
    function($v) {
      return {
        "8": {"value":

```

would be my guess.

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [12 November 2025 18:12 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/7 "2025-11-12T18:12:15Z")

</div>

> [@Steve-Mcl](#):
>
> By my crude reckoning (and some research), there are ~10k JSONata devs

Plus 1 dev as [JSONata-to-Erlang](https://github.com/gorenje/erlang-red-jsonata) parser - so that would be really niche!

---

<div class="post-metadata">

**Author:** ![dubnemo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dubnemo/32/38759_2.png) [@dubnemo](https://discourse.nodered.org/u/dubnemo)\
**Post date:** [12 November 2025 18:20 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/8 "2025-11-12T18:20:22Z")

</div>

Well, interesting the LLM produced similar but different 'corrections' Changing the from my single quote to double quote on my concatentation made not difference, but the double bracket approach that ChatGPT recommended {{ code }} versus the bracket - paren approach {( code )} that Gemini suggested did resolve the issue.

I DID ask Gemini to rewrite my JSONata into Javascript for the Change node and that actually worked pretty well, even offering parameter checks and proper flow.get calls:

```auto
// Retrieve the necessary data from the flow context (similar to JSONata's flow variable)
// Note: In a real Node-RED flow, ensure 'flow.shipmentContents' and 'flow.foreignKeyId'
// are correctly set in previous nodes and stored in the flow context.
const shipmentContents = flow.get('shipmentContents') || [];
const foreignKeyId = flow.get('foreignKeyId');

// Check if we have data to process
if (!Array.isArray(shipmentContents) || shipmentContents.length === 0 || !foreignKeyId) {
    // Optionally handle error or return early if data is missing
    node.warn("Missing or invalid shipment contents or foreign key ID in flow context.");
    return null; // Stop the flow here
}

// Generate the Quickbase payload data array using .map()
const dataArray = shipmentContents.map(item => {
    // Create the object for each record
    return {
        "8": { "value": `${item.SALES_ORDER_ID}-${item.DOCUMENT_TYPE}-${item.LINE_ID}` },
        "9": { "value": item.LINE_TYPE },
        "11": { "value": item.GTIN },
        "12": { "value": item.ITEM_DESCRIPTION },
        "13": { "value": item.ALT_DESCRIPTION },
        "14": { "value": item.DESCRIPTION },
        "15": { "value": item.QUANTITY_ORDERED - item.QUANTITY_SHIPPED },
        "16": { "value": item.QUANTITY_ORDERED },
        "22": { "value": foreignKeyId }
    };
});

// Assemble the final payload object which will be returned by the function node
msg.payload = {
    "to": "bvhw2455g",
    "data": dataArray,
    "fieldsToReturn": [
        1,
        2
    ]
};

// Return the message object with the newly constructed payload
return msg;

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 November 2025 18:20 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/9 "2025-11-12T18:20:23Z")

</div>

> [@dubnemo](#):
>
> `flow.shipmentContents`

Is this a context value or a msg var name?  
is there any imput dat example to view?

---

<div class="post-metadata">

**Author:** ![dubnemo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dubnemo/32/38759_2.png) [@dubnemo](https://discourse.nodered.org/u/dubnemo)\
**Post date:** [12 November 2025 18:21 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/10 "2025-11-12T18:21:23Z")

</div>

context value .. it works.

Unfortunately, no data to share here. This is production data from a Dairy manufacturing plant that makes 10% of the butter for the entire USA.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 November 2025 18:22 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/11 "2025-11-12T18:22:24Z")

</div>

In JSONata it would be `$flowContext("shipmentContents")`

So can you create a simple example of the input  
a two element array.

---

<div class="post-metadata">

**Author:** ![dubnemo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dubnemo/32/38759_2.png) [@dubnemo](https://discourse.nodered.org/u/dubnemo)\
**Post date:** [12 November 2025 18:24 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/12 "2025-11-12T18:24:42Z")

</div>

OK good to know. I went the Javascript route for now.  
@E1cid  
Does that $flowContext imply a Javascript callout? Can $ be used to callout to my own Javascript functions to extend JSONata?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [12 November 2025 18:43 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/13 "2025-11-12T18:43:49Z")

</div>

> [@E1cid](#):
>
> In JSONata it would be `$flowContext("shipmentContents")`

Chatgpt initially told me that flow.shipmentContents was invalid, it should be flow("shipmentContents") but in her 'corrected' jsonata she went back to the original.  
When I questioned this she declared that flow.shipmentContents is perfectly OK. Maybe she was thinking of msg.flow.shipmentContents ...

Now I come to think of it, I don't believed she mentioned how smart I was to raise the question. Mutter mutter.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 November 2025 19:00 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/14 "2025-11-12T19:00:42Z")

</div>

$flowContext() and $globalContext() is a node-red extension to JSONata for context vars, as is $moment() a JSONata extension for moment js.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 November 2025 19:06 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/15 "2025-11-12T19:06:56Z")

</div>

IF Chatgpt sort counselling they would diagnose it a people pleaser.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 November 2025 20:09 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/16 "2025-11-12T20:09:14Z")

</div>

And a deluded liar!

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [19 November 2025 14:39 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/17 "2025-11-19T14:39:29Z")

</div>

> [@dubnemo](#):
>
> `"8": {"value": $v.SALES_ORDER_ID & '-' $v.DOCUMENT_TYPE & '-' & $v.LINE_ID}`

In your function, you needed to return an object as @jbudd added in his fixed code.  
You were also missing the string concat symbol before the document\_type:

```auto
{"value": $v.SALES_ORDER_ID & '-' & $v.DOCUMENT_TYPE & '-' & $v.LINE_ID}
                                  ^ (here)

```

Personally for me, I find the JSONata syntax more "self-docmenting" as far as how I want the output to appear - at least for simple json restructuring. Granted it requires some knowledge of the syntax to write it, but when I come back to look at it later I see the data more than the code used to create the data... just like using regex to pull apart strings (but I'm odd that way).

In the future, it would be more helpful if you also posted a sample of the `shipmentContents` array for us to test alternative expressions. Even better is to post a link to saved JSONata expression in the online test site -- such as this [simplified expression](https://try.jsonata.org/HH9exzSU8) (minus the flow vars)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 December 2025 14:40 UTC](https://discourse.nodered.org/t/jsonata-exception-jsonata-expression-help-please/99658/18 "2025-12-03T14:40:07Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
