Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json function to output value as JSON #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

koenpunt
Copy link

@koenpunt koenpunt commented Jul 16, 2019

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 }}

for easy representation of json values I've added a JSON function that feeds the value to the json marshaller.
@koenpunt
Copy link
Author

Ping ✨

@sagikazarmark
Copy link

Would toJson implemented in #140 work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants