to_nice_json¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in versionhistorical.
Synopsis¶
- Converts an Ansible variable into a 'nicely formatted' JSON string representation
- This filter functions as a wrapper to the Python C(json.dumps) function.
- Ansible automatically converts JSON strings into variable structures so this plugin is used to forcibly retain a JSON string.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _input raw required |
A variable or expression that returns a data structure. | |
| allow_nan bool |
Default: True |
When V(False), out-of-range float values C(nan), C(inf) and C(-inf) will result in an error. When V(True), out-of-range float values will be represented using their JavaScript equivalents, C(NaN), C(Infinity) and C(-Infinity). |
| check_circular bool |
Default: True |
Controls the usage of the internal circular reference detection, if off can result in overflow errors. |
| ensure_ascii bool |
Default: True |
Escapes all non ASCII characters. |
| indent int |
Default: 4 |
Specifies an indentation level. Passed to an underlying C(json.dumps) call. |
| preprocess_unsafe bool |
Default: True |
Toggle to represent unsafe values directly in JSON or create a unsafe object in JSON. Version Added: 2.9 |
| skipkeys bool |
If V(True), keys that are not basic Python types will be skipped. | |
| sort_keys bool |
Default: True |
Affects sorting of dictionary keys. Passed to an underlying C(json.dumps) call. |
| vault_to_text bool |
Default: True |
Toggle to either unvault a vault or create the JSON version of a vaulted object. Version Added: 2.9 |
Notes¶
Note
- Both O(vault_to_text) and O(preprocess_unsafe) defaulted to V(False) between Ansible 2.9 and 2.12.
- These parameters to C(json.dumps) will be ignored, they are overridden for internal use: I(cls), I(default), I(separators).
Examples¶
# dump variable in a template to create a nicely formatted JSON document
{{ docker_config | to_nice_json }}
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | string | The 'nicely formatted' JSON serialized string representing the variable structure inputted. |
Authors¶
- Core Team