node-red / node-red/node-red

Jsonata editor test error with transform function (3.1.3)

Open
#4,504 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug editor
Dominant language
JavaScript
Stars
23.7k
Forks
3.9k
Avg merge
12h 23m
Merged PRs (30d)
22

Description

Current Behavior

I have just updated a node-red server to 3.1.3 and have notice a bug in the JSONata test enviroment in the change node editor.

Prior to update 3.1 this used to work fine.

If you set an array of objects in payload in the test window

{
    "payload": [
        {
            "w1": "This",
            "w2": "is",
            "w3": "Big!"
        },
        {
            "w1": "Big",
            "w2": "as",
            "w3": "this?"
        }
    ]
}

Then use this expression containing the transform function

$$.payload ~> |$|
 {"a":"a"}
|

An error is reported

Error evaluating expression:
  Cannot set properties of null (setting 'a')

The expression will run just fine and produce an
output

{
    "_msgid": "b5e1ea5de4e4373f",
    "payload": [
        {
            "w1": "This",
            "w2": "is",
            "w3": "Big!",
            "a": "a"
        },
        {
            "w1": "Big",
            "w2": "as",
            "w3": "this?",
            "a": "a"
        }
    ],
    "topic": ""
}

I have checked and no error is shown on a node-red 2.3 server, and i am fairly sure it worked on 3.0 to.

Expected Behavior

Not to show error as using tranform function in test panel worked fine prior to update to 3.1.3

Steps To Reproduce

As described above

Example flow
[
    {
        "id": "d115287648de5277",
        "type": "inject",
        "z": "d1395164b4eec73e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[{\"w1\":\"This\",\"w2\":\"is\",\"w3\":\"Big!\"},{\"w1\":\"Big\",\"w2\":\"as\",\"w3\":\"this?\"}]",
        "payloadType": "json",
        "x": 110,
        "y": 2500,
        "wires": [
            [
                "8c8a243c01c3e7b0"
            ]
        ]
    },
    {
        "id": "8c71a0febf7bcd4d",
        "type": "debug",
        "z": "d1395164b4eec73e",
        "name": "debug 8",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 2500,
        "wires": []
    },
    {
        "id": "8c8a243c01c3e7b0",
        "type": "change",
        "z": "d1395164b4eec73e",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$$.payload ~> |$|\t {\"a\":\"a\"}\t|",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 300,
        "y": 2500,
        "wires": [
            [
                "8c71a0febf7bcd4d"
            ]
        ]
    }
]
Environment
  • Node-RED version: 3.1.3
  • Node.js version: 20.2.0
  • npm version: 9.6.6
  • Platform/OS: turmux
  • Browser: chrome

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the transform expression in the Change node editor's JSONata test panel using the supplied payload and example flow. Trace why the test panel reports the null-property error even though the expression runs successfully, then verify that the panel shows no error and preserves the expected transformed output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.