Note
This filter plugin is part of the community.general collection (version 10.7.3).
You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this filter plugin, see Requirements for details.
To use it in a playbook, specify: community.general.json_diff.
New in community.general 10.3.0
The below requirements are needed on the local controller node that executes this filter.
This describes the input of the filter, the value before | community.general.json_diff.
Parameter | Comments |
|---|---|
Input any / required | A list or a dictionary representing a source JSON object, or a string containing a JSON object. |
This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | community.general.json_diff(positional1, positional2, ...)
Parameter | Comments |
|---|---|
target any / required | A list or a dictionary representing a target JSON object, or a string containing a JSON object. |
See also
JavaScript Object Notation (JSON) Patch
JavaScript Object Notation (JSON) Pointer
A Python library for applying JSON patches
- name: Compute a difference
ansible.builtin.debug:
msg: "{{ input | community.general.json_diff(target) }}"
vars:
input: {"foo": 1, "bar":{"baz": 2}, "baw": [1, 2, 3], "hello": "day"}
target: {"foo": 1, "bar": {"baz": 2}, "baw": [1, 3], "baq": {"baz": 2}, "hello": "night"}
# => [
# {"op": "add", "path": "/baq", "value": {"baz": 2}},
# {"op": "remove", "path": "/baw/1"},
# {"op": "replace", "path": "/hello", "value": "night"}
# ]
Key | Description |
|---|---|
Return value list / elements=dictionary | A list of JSON patch operations to apply. Returned: success |
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/general/json_diff_filter.html