Home > Blockchain >  Inserting variables into JSON data
Inserting variables into JSON data

Time:06-24

I'm using https://github.com/jerosoler/Drawflow plugin, but I'm trying to add a few variables to the strings written below, but I can't.

var data= {
    "drawflow": {
        "Home": {
            "data": {}
        },
        "Other": {
            "data": {
                "16": {
                    "id": 16,
                    "name": "Michael",
                    "data": {},
                    "class": "michael"                  
                }                
            }
        }
    }
}

i want to do but I can't add my variables is there any other way; Unexpected token gives ' ' error when I add it as "'" variable "'"

var int= 2;
var string="car";

"data": {
                int: {
                    "id": int,
                    "name": string,
                    "data": {},
                    "class": string,                
                    "inputs": {}
                }

CodePudding user response:

You could use string interpolation like so:

var int= 2;
var string="car";

"data": {
                int: {
                    "id": `${int}`,
                    "name": `${string},
                    "data": {},
                    "class": `${string}`,                
                    "inputs": {}
                }

the special quotes `` make it so you can insert variables with ${}

CodePudding user response:

It gives an error when I do as you say.

Error:Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Element': '.node_out_node-${a}' is not a valid selector.

  • Related