diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2017-03-06 16:41:28 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2017-03-06 20:08:33 -0500 |
| commit | 7b6434d5784b811d4a3e5b663cfacd2716bd7db9 (patch) | |
| tree | 1a557a2e158e78f60f8750d7ba220d3a3231354f /README.md | |
| parent | 198c1145bdf4ee94342f0c282f8294561e0419c0 (diff) | |
Adding toJSON and toYAML functions
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 43 |
1 files changed, 42 insertions, 1 deletions
@@ -67,6 +67,10 @@ Gomplate is an alternative that will let you process templates which also includ - [Example](#example) - [`yamlArray`](#yamlarray) - [Example](#example) + - [`toJSON`](#tojson) + - [Example](#example) + - [`toYAML`](#toyaml) + - [Example](#example) - [`datasource`](#datasource) - [Examples](#examples) - [Basic usage](#basic-usage) @@ -111,7 +115,7 @@ $ apk add gomplate ... ``` -_Note: the Alpine version of gomplate may lag behind the latest release of gomplate._ +_Note: the Alpine version of gomplate may lag behind the latest release of gomplate._ ### use with Docker @@ -453,6 +457,43 @@ $ gomplate < input.tmpl Hello world ``` +#### `toJSON` + +Converts an object to a JSON document. Input objects may be the result of `json`, `yaml`, `jsonArray`, or `yamlArray` functions, or they could be provided by a `datasource`. + +##### Example + +_This is obviously contrived - `json` is used to create an object._ + +_`input.tmpl`:_ +``` +{{ (`{"foo":{"hello":"world"}}` | json).foo | toJSON }} +``` + +```console +$ gomplate < input.tmpl +{"hello":"world"} +``` + +#### `toYAML` + +Converts an object to a YAML document. Input objects may be the result of `json`, `yaml`, `jsonArray`, or `yamlArray` functions, or they could be provided by a `datasource`. + +##### Example + +_This is obviously contrived - `json` is used to create an object._ + +_`input.tmpl`:_ +``` +{{ (`{"foo":{"hello":"world"}}` | json).foo | toYAML }} +``` + +```console +$ gomplate < input.tmpl +hello: world + +``` + #### `datasource` Parses a given datasource (provided by the [`--datasource/-d`](#--datasource-d) argument). |
