Closed AbdouMechraoui closed 7 months ago
You can use env.policies["json.dumps_kwargs"] = {...}
to set other arguments for every call to tojson
. I don't plan to add individual arguments to this filter. Note that indent
will already not work if using a different JSON library that doesn't use the same arguments, like orjson.dumps
. You can also override the filter to do what you want instead with env.filters["tojson"] = my_tojson
.
Thanks for the prompt response. All options you have mentioned require access to the environment policy, which is not possible since I am using a stable AWX release. Is it possible to change or modify the environment policy in a template file?
As per your second point, this can be avoided perhaps if the do_tojson()
method accepts **kwargs
instead of individual arguments.
Hello, I am using jinja2 templating in the context of AWX. There are certain templates in AWX that only allow builtin jinja2 filters to be used, such as the Notification-Templates. The issue that I am dealing with relates to the inability to unset the
sort_keys
flag in the environment policy. Although JSON is an unordered set, sometimes sorting is not desired.It would be nice to enable or disable this flag through a filter parameter, when the user does not have access to the environment policies. Currently, one can control the indentation through parameter
indent
. The parametersort_keys
should function the same way.tldr: It would be nice to control the sorting behavior of
tojson
through parametersort_keys
.Current implementation
tojson
:This produces the following:
Desired implementation
tojson
:This should produce the following:
I would be happy to add a PR, if you'd entertain it :D