Return a JSON from Template Node

I am trying to return a JSON from a template but I get errors when I set the template node to "Parsed JSON".
The error says "Unexpected token : in JSON at position 13"
This is the content of the template node:

"GPIO_status": "{{global.GPIOStatus}}"

It works if I use a string instead of the variable but I need to use the variable.

[
    {
        "id": "790ce3dd056171ab",
        "type": "http in",
        "z": "2879f16a7e5f317b",
        "name": "Input from KIosk",
        "url": "/api/9999",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 600,
        "y": 980,
        "wires": [
            [
                "74a459e814c726ae"
            ]
        ]
    },
    {
        "id": "3b704fe84da208bb",
        "type": "http response",
        "z": "2879f16a7e5f317b",
        "name": "",
        "statusCode": "200",
        "headers": {},
        "x": 960,
        "y": 980,
        "wires": []
    },
    {
        "id": "74a459e814c726ae",
        "type": "template",
        "z": "2879f16a7e5f317b",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "\"GPIO_status\": \"{{global.GPIOStatus}}\"\n",
        "output": "json",
        "x": 780,
        "y": 980,
        "wires": [
            [
                "3b704fe84da208bb"
            ]
        ]
    }
]

Even after the global var is replaced by mustache, that is not valid JSON.

https://codebeautify.org/jsonvalidator/y234d047e

Try wrapping it in { curly } brackets

1 Like

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