Skip to content

Commit b225a0e

Browse files
committed
doc: document the json_to_yaml, and yaml_to_json template helper functions
1 parent 3887666 commit b225a0e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

docs/render/using-built-in-helpers.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using Built-in Helpers
22
<!--
3-
Copyright 2024 Google LLC
3+
Copyright 2025 Google LLC
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -220,8 +220,33 @@ The file path is relative to the main template file directory.
220220
}
221221
```
222222

223-
224223

224+
### **json_to_yaml**
225+
```go
226+
func json_to_yaml(json string) string
227+
```
228+
229+
Converts the input JSON string to YAML.
230+
231+
e.g.
232+
```gotemplate
233+
{{ $YAML_TEXT := `{"hello":"world"}` | json_to_yaml }}
234+
{{ print $YAML_TEXT }}
235+
```
236+
237+
238+
### **yaml_to_json**
239+
```go
240+
func yaml_to_json(yaml string) string
241+
```
242+
243+
Converts the input YAML string to JSON.
244+
245+
e.g.
246+
```gotemplate
247+
{{ $YAML_TEXT := `{"hello":"world"}` | json_to_yaml }}
248+
{{ print (yaml_to_json $YAML_TEXT) }}
249+
```
225250

226251
## Libraries
227252
### **Sprig**

pkg/common/resources/helper_functions.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@
124124
}
125125
}
126126

127+
json_to_yaml(string) string
128+
Converts the input JSON string to YAML. e.g.
129+
130+
{{ $YAML_TEXT := `{"hello":"world"}` | json_to_yaml }}
131+
{{ print $YAML_TEXT }}
132+
133+
yaml_to_json(string) string
134+
Converts the input YAML string to JSON
135+
136+
{{ $YAML_TEXT := `{"hello":"world"}` | json_to_yaml }}
137+
{{ print (yaml_to_json $YAML_TEXT) }}
138+
139+
127140
Sprig
128141
Template functions from Sprig library
129142
e.g. {{ "Hello World" | upper }}

0 commit comments

Comments
 (0)