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

config: jinja2 "tojson" template filter to use custom JSONEncoder class #57

Merged
merged 1 commit into from
Mar 17, 2024

Conversation

robvdl
Copy link
Member

@robvdl robvdl commented Mar 17, 2024

This is similar to renderers.py, unfortunately it isn't really possible to share code here.

This is because the JSON renderer uses adapters through add_adapter, while the jinja2 template tag needs a custom JSONEncoder class instead.

You cannot pass a default= argument when constructing the JSON renderer constructor, as it already does this internally, resulting in an error that default= is listed twice.

Closes #56

This is similar to renderers.py, unfortunately it isn't really possible to share code here.

This is because the JSON renderer uses adapters through add_adapter, while the jinja2 template tag needs a custom JSONEncoder class instead.

You cannot pass a default= argument when constructing the JSON renderer constructor, as it already does this internally, resulting in an error that default= is listed twice.

Closes #56
@robvdl robvdl merged commit 75b54fe into master Mar 17, 2024
1 check passed
@robvdl robvdl deleted the jinja2-json-config branch March 17, 2024 10:15
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.

Jinja2 filter |tojson should use Sambal adapters for datatypes
1 participant