1

I'm having trouble with this snippet where I want to pass in value using a variable but it becomes a literal string.

test: if variableA then {
  'hello': '{"foo": bar}'
},

I want to be to be variable and I expect bar to be the value I've passed in as a parameter but it is literally the word bar

hitman222
  • 179
  • 4
  • 10

1 Answers1

1

The question is lacking a little context, such as how bar was assigned, and perhaps why you are trying to write an object as a string literal.

Assuming there is a value assigned to bar somewhere, on way to write this would be to use string interpolation:

test: if variableA then {
  hello: '{"foo": %s}' % bar
}

Also, key names only need to be quoted if they contain unsupported characters.

john
  • 140
  • 6