jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

How to use variable on left side ?

Open salimuddin87 opened this issue 6 years ago • 2 comments

This is basic syntax of datadog annotation I am trying to convert in jsonnet. ad.datadoghq.com/<CONTAINER_IDENTIFIER>.logs : '[<LOG_CONFIG>]'

CONTAINER_IDENTIFIER will be different for each container.

salimuddin87 avatar Jun 12 '20 16:06 salimuddin87

Do you mean using a variable in the field name?

You can do it as follows:

local var = "foo";
{
   ["bar" + var + "baz"]: 42
}

which results in:

{
  "barfoobaz": 42
}

There's a section in the tutorial about this: https://jsonnet.org/learning/tutorial.html#computed_field_names.

Please note that Github issues are not meant for basic language usage questions. Please consider posting such questions on Stackoverflow with a tag jsonnet, asking in the mailing list https://groups.google.com/forum/#!forum/jsonnet or on #jsonnet slack channel on https://kubernetes.slack.com/. Feel free to open an issue if you don't get a satisfying answer in one of these, if you suspect that there might be a bug, you have a feature request, a question about best practices or any other issue that the language developers should get involved in.

sbarzowski avatar Jun 12 '20 17:06 sbarzowski

Thanks @sbarzowski It was really helpful

salimuddin87 avatar Jun 13 '20 04:06 salimuddin87