Embed JavaScript variable to JSON

I want to inject a js variable into json (to show the message at slack). I tested this:

 "fields":[  
     {  
        "title": "Reported by:",
        "value": "'+ user + '",
        "short": "false"
     },

      

but it doesn't work and shows me the following:

Sent by:

'+ user +'

Thanks you!

+3


source to share


2 answers


It seems to me that you should be doing something like:

"value": "'" + user + "'",



Before the user was still part of the string expression.

+1


source


This is called string concatenation:

 {  
    "title": "Reported by:",
    "value": "'" + user + "'",
    "short": "false"
 }

      



value

will create a string with combined values, for example if user

it was a string value "Jamen"

then the concatenated value value

would be"'Jamen'"

+1


source







All Articles