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 parser function to Jinja2 templates #2120

Merged
3 commits merged into from
Oct 29, 2021

Conversation

creideiki
Copy link
Contributor

In our use cases, we sometimes have some JSON data that we want to format nicely for sending to another system via e-mail. We currently do that by having entire expert bots just to format the data into a string to go in the output field of a message, which seems wasteful.

With this patch, the Jinja2 template environment gains a function from_json() (which just calls json.loads() in the standard Python environment), meaning the Templated SMTP output bot can take strings containing JSON documents and do the formatting itself.

Jinja2 has a JSON serializer, but not a parser. This is the source of
many StackOverflow questions and bug reports to projects using Jinja2.
Add a function "from_json", which just calls "json.loads", to
templates so that they can handle the JSON string in the "output"
field of an event.
Copy link
Contributor

@waldbauer-certat waldbauer-certat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me

@ghost ghost added this to the 3.1.0 milestone Oct 29, 2021
@ghost ghost added component: bots feature Indicates new feature requests or new features labels Oct 29, 2021
@ghost ghost self-assigned this Oct 29, 2021
@ghost ghost merged commit 8337d74 into certtools:develop Oct 29, 2021
@creideiki creideiki deleted the jinja-parse-json branch October 31, 2021 18:15
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: bots feature Indicates new feature requests or new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants