ansible / ansible.builtin / v2.15.2 / filter / to_json Convert variable to JSON string | "added in version" historical of ansible.builtin" Authors: core teamansible.builtin.to_json (v2.15.2) — filter
pip
Install with pip install ansible-core==2.15.2
Converts an Ansible variable into a JSON string representation.
This filter functions as a wrapper to the Python C(json.dumps) function.
Ansible internally auto-converts JSON strings into variable structures so this plugin is used to force it into a JSON string.
_input: description: A variable or expression that returns a data structure. required: true type: raw indent: default: 0 description: Number of spaces to indent Python structures, mainly used for display to humans. type: integer skipkeys: default: false description: If C(True), keys that are not basic Python types will be skipped. type: bool allow_nan: default: true description: When C(False), strict adherence to float value limits of the JSON specifications, so C(nan), C(inf) and C(-inf) values will produce errors. When C(True), JavaScript equivalents will be used (C(NaN), C(Infinity), C(-Infinity)). type: bool sort_keys: default: false description: Affects sorting of dictionary keys. type: bool separators: default: '('', '', '': '')' description: The C(item) and C(key) separator to be used in the serialized output, default may change depending on I(indent) and Python version. type: tuple ensure_ascii: default: true description: Escapes all non ASCII characters. type: bool vault_to_text: default: true description: Toggle to either unvault a vault or create the JSON version of a vaulted object. type: bool version_added: '2.9' version_added_collection: ansible.builtin check_circular: default: true description: Controls the usage of the internal circular reference detection, if off can result in overflow errors. type: bool preprocess_unsafe: default: true description: Toggle to represent unsafe values directly in JSON or create a unsafe object in JSON. type: bool version_added: '2.9' version_added_collection: ansible.builtin
_value: description: The JSON serialized string representing the variable structure inputted. type: string