dockerize icon indicating copy to clipboard operation
dockerize copied to clipboard

Add json function to output value as JSON

Open koenpunt opened this issue 5 years ago • 2 comments

For easy representation of json values I've added a JSON function that feeds the value to the json marshaller.

The signature has a variable number of arguments, where the first is the data to marshal, the second (optional) argument is the prefix (to match existing indentation), and the third (optional) argument is the indentation to use.

Contrived example:

{{ with $jsonDoc := `{
  "services": [
    {
      "name": "service1",
      "port": 8000
    }, {
      "name": "service2",
      "port": 9000
    }
  ]
}` }}
{{- $services := jsonQuery $jsonDoc "services" -}}
{
  "services": {{ json $services "  " "  " }}
}
{{ end }}

koenpunt avatar Jul 16 '19 11:07 koenpunt

Ping ✨

koenpunt avatar Nov 13 '19 23:11 koenpunt

Would toJson implemented in #140 work for you?

sagikazarmark avatar Jan 01 '21 14:01 sagikazarmark