ansible.builtin.from_json filter – Convert JSON string into variable structure

Note

This filter plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name from_json even without specifying the collections: keyword. However, we recommend you use the FQCN for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.

Synopsis

  • Converts a JSON string representation into an equivalent structured Ansible variable.

  • Ansible automatically converts JSON strings into variable structures in most contexts, use this plugin in contexts where automatic conversion does not happen.

Input

This describes the input of the filter, the value before | ansible.builtin.from_json.

Parameter

Comments

Input

string / required

A JSON string.

Notes

Note

  • This filter functions as a wrapper to the Python json.loads function.

Examples

# variable from string variable containing a JSON document
{{ docker_config | from_json }}

# variable from string JSON document
{{ '{"a": true, "b": 54, "c": [1,2,3]}' | from_json }}

Return Value

Key

Description

Return value

any

The variable resulting from deserialization of the JSON document.

Returned: success

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.