Inject JSON data to a web form

Hey All,
I'm learning how to work with JSON in Node Red and I'm trying to inject some JSON data into a web form so I can work on it from the back end.

On the inject node I'm using Inject --> JSON and I've tried a bunch of variation but nothing is working.

What I think it should be is

{ "PIRApt" : "1" }

When I try this it says it was successfully injected but I don't see anything in the debug console. What's happening?

[
    {
        "id": "bf688d57fb5707dd",
        "type": "debug",
        "z": "574d186f6c85309d",
        "name": "debug 166",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 340,
        "wires": []
    },
    {
        "id": "2f5644744a11ca4c",
        "type": "json",
        "z": "574d186f6c85309d",
        "name": "JS OBJECT",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 470,
        "y": 340,
        "wires": [
            [
                "bf688d57fb5707dd"
            ]
        ]
    },
    {
        "id": "f3cb687d4d24761b",
        "type": "ui_form",
        "z": "574d186f6c85309d",
        "name": "",
        "label": "",
        "group": "3312af4f71436b3c",
        "order": 7,
        "width": 0,
        "height": 0,
        "options": [
            {
                "label": "aptPIR",
                "value": "aptPIR",
                "type": "number",
                "required": false,
                "rows": null
            },
            {
                "label": "aptBrightness",
                "value": "aptBrightness",
                "type": "number",
                "required": false,
                "rows": null
            },
            {
                "label": "aptTimerLength",
                "value": "aptTimerLength",
                "type": "number",
                "required": false,
                "rows": null
            }
        ],
        "formValue": {
            "aptPIR": "",
            "aptBrightness": "",
            "aptTimerLength": ""
        },
        "payload": "",
        "submit": "submit",
        "cancel": "",
        "topic": "payload",
        "topicType": "msg",
        "splitLayout": "",
        "className": "",
        "x": 330,
        "y": 340,
        "wires": [
            [
                "2f5644744a11ca4c"
            ]
        ]
    },
    {
        "id": "a0375ba6b54b914c",
        "type": "inject",
        "z": "574d186f6c85309d",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"aptPIR\" : \"1\"}",
        "payloadType": "json",
        "x": 160,
        "y": 340,
        "wires": [
            [
                "f3cb687d4d24761b"
            ]
        ]
    },
    {
        "id": "3312af4f71436b3c",
        "type": "ui_group",
        "name": "JSON",
        "tab": "c548a45fe690539c",
        "order": 11,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "c548a45fe690539c",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": true
    }
]

aptPIR in the form is type number, you are trying to set it to "1" string

OK, I see that now. It should like this yes?

{"aptPIR" : 1}

Still doesn't work

Works here you must be doing something else different

hmm, this is what I have

[
    {
        "id": "a0375ba6b54b914c",
        "type": "inject",
        "z": "574d186f6c85309d",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"aptPIR\" : 1}",
        "payloadType": "json",
        "x": 150,
        "y": 340,
        "wires": [
            [
                "f3cb687d4d24761b"
            ]
        ]
    },
    {
        "id": "f3cb687d4d24761b",
        "type": "ui_form",
        "z": "574d186f6c85309d",
        "name": "",
        "label": "",
        "group": "3312af4f71436b3c",
        "order": 7,
        "width": 0,
        "height": 0,
        "options": [
            {
                "label": "aptPIR",
                "value": "aptPIR",
                "type": "number",
                "required": false,
                "rows": null
            },
            {
                "label": "aptBrightness",
                "value": "aptBrightness",
                "type": "number",
                "required": false,
                "rows": null
            },
            {
                "label": "aptTimerLength",
                "value": "aptTimerLength",
                "type": "number",
                "required": false,
                "rows": null
            }
        ],
        "formValue": {
            "aptPIR": "",
            "aptBrightness": "",
            "aptTimerLength": ""
        },
        "payload": "",
        "submit": "submit",
        "cancel": "",
        "topic": "payload",
        "topicType": "msg",
        "splitLayout": "",
        "className": "",
        "x": 310,
        "y": 340,
        "wires": [
            [
                "2f5644744a11ca4c"
            ]
        ]
    },
    {
        "id": "2f5644744a11ca4c",
        "type": "json",
        "z": "574d186f6c85309d",
        "name": "JS OBJECT",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 490,
        "y": 340,
        "wires": [
            [
                "bf688d57fb5707dd"
            ]
        ]
    },
    {
        "id": "bf688d57fb5707dd",
        "type": "debug",
        "z": "574d186f6c85309d",
        "name": "debug 166",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 340,
        "wires": []
    },
    {
        "id": "3312af4f71436b3c",
        "type": "ui_group",
        "name": "JSON",
        "tab": "c548a45fe690539c",
        "order": 11,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "c548a45fe690539c",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": true
    }
]```

Your flow works for me to, even with the unneeded JSON node.
What version of dashboard are you using?

hmmm, it's the current version 3.3.1

Note, I do see the results when I fill out the form from the front end.

What version of NR?

I see output in the debug node whither pressing the inject or entering data on the form.

Try restarting NR and flushing your browsers cache.

tried restarting and flusing the browser...still no beans. Weird. Thanks guys for helping so far.

Just to be sure.
The inject will only populate the form, it will not submit it.

Do you have your debug node (set to display the complete msg object)? Also try adding a catch node connected to another debug (node set to display the complete msg object)

As @E1cid said, go to the form and press the 'SUBMIT'

OK thank you! you've identified the problem. Now what?

define what please.

If you want to submit straight from the inject bypass the form
e.g.

[{"id":"45f56547d653956c","type":"inject","z":"d6c1f08ec046990c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"aptPIR\":1,\"aptBrightness\":null,\"aptTimerLength\":null}","payloadType":"json","x":150,"y":320,"wires":[["08961f444a46c69b","c22d5ce3d5431999"]]},{"id":"08961f444a46c69b","type":"debug","z":"d6c1f08ec046990c","name":"debug 166","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":340,"wires":[]},{"id":"c22d5ce3d5431999","type":"junction","z":"d6c1f08ec046990c","x":240,"y":380,"wires":[["4014f03cab2cf0d8"]]},{"id":"4014f03cab2cf0d8","type":"ui_form","z":"d6c1f08ec046990c","name":"","label":"","group":"3312af4f71436b3c","order":7,"width":0,"height":0,"options":[{"label":"aptPIR","value":"aptPIR","type":"number","required":false,"rows":null},{"label":"aptBrightness","value":"aptBrightness","type":"number","required":false,"rows":null},{"label":"aptTimerLength","value":"aptTimerLength","type":"number","required":false,"rows":null}],"formValue":{"aptPIR":"","aptBrightness":"","aptTimerLength":""},"payload":"","submit":"submit","cancel":"","topic":"payload","topicType":"msg","splitLayout":"","className":"","x":350,"y":380,"wires":[["08961f444a46c69b","c22d5ce3d5431999"]]},{"id":"3312af4f71436b3c","type":"ui_group","name":"JSON","tab":"c548a45fe690539c","order":11,"disp":true,"width":"6","collapse":false,"className":""},{"id":"c548a45fe690539c","type":"ui_tab","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

If you want to reload the data to the form after a submit, loop the output back to the input.

1 Like

Thank You! Much gratitude.

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