Templating specific keys in arbitrarily nested JSON #2052
Replies: 1 comment
-
If I'm understanding this correctly you just want to have a JSON file where some strings might contain template strings? If so, you just need to treat the JSON file as a template file itself and run it through gomplate as usual. Something like: input.json: [
{
"sections": [
...
"Chapter": {
"content": "{{ printf "some probably more complex template string" }}",
"sub_items": [
{
"Chapter": {
"content": "{{ ... }}",
}
...
] If you wanted to reference data defined in the JSON file itself you could use the file as both the template and a datasource or context value (though you'd be referencing the pre-rendered template): $ gomplate -c data=input.json -f input.json
...
I don't know that I understand what you mean here, but check out the |
Beta Was this translation helpful? Give feedback.
-
Hey all 👋
So, I'm being handed some JSON in a pretty nested form, and I'd like to:
Chapter.content
field, wherever it appears in the nested data;I guess that, if there were a way of satisfying point (2) then I could simply template the stringified form of the JSON document in one go, but that /feels/ tricky to do.
Here's an example of the form. The
sub_items
list could be nested more deeply than this example, but I won't know its structure in advance:Is this achievable using Gomplate?
If not, what's the smallest structural modification I could make to the data such that it would be possible?
Small addendum
Is it possible to only emit the (templated, as discussed above) 2nd list item from the top-level list I'm given?
Beta Was this translation helpful? Give feedback.
All reactions