community.general.json_patch_recipe filter – Apply JSON-Patch (RFC 6902) operations to an object
Note
This filter plugin is part of the community.general collection (version 12.6.1).
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_patch_recipe.
New in community.general 10.3.0
Synopsis
- This filter sequentially applies JSON patch operations and returns a modified object.
- If there is a test operation in the list, the filter continues if the test succeeded and returns a
nonevalue otherwise.
Requirements
The below requirements are needed on the local controller node that executes this filter.
- jsonpatch
Input
This describes the input of the filter, the value before | community.general.json_patch_recipe.
Parameter | Comments |
|---|---|
Input any / required | A list or a dictionary representing a JSON object, or a string containing a JSON object. |
Positional parameters
This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | community.general.json_patch_recipe(positional1, positional2, ...)
Parameter | Comments |
|---|---|
operations list / elements=dictionary / required | A list of JSON patch operations to apply. |
|
from string |
The source location for the copy and move operation. Mandatory for |
|
op string / required | |
|
path string / required |
JSON Pointer path to the target location (see RFC 6901). |
|
value any |
Value to use in the operation. Ignored for |
fail_test boolean | If Choices:
|
See Also
See also
- RFC 6902
-
JavaScript Object Notation (JSON) Patch
- RFC 6901
-
JavaScript Object Notation (JSON) Pointer
- jsonpatch Python Package
-
A Python library for applying JSON patches
Examples
- name: Apply a series of operations
ansible.builtin.debug:
msg: "{{ input | community.general.json_patch_recipe(operations) }}"
vars:
input: {}
operations:
- op: 'add'
path: '/foo'
value: 1
- op: 'add'
path: '/bar'
value: []
- op: 'add'
path: '/bar/-'
value: 2
- op: 'add'
path: '/bar/0'
value: 1
- op: 'remove'
path: '/bar/0'
- op: 'move'
from: '/foo'
path: '/baz'
- op: 'copy'
from: '/baz'
path: '/bax'
- op: 'copy'
from: '/baz'
path: '/bay'
- op: 'replace'
path: '/baz'
value: [10, 20, 30]
# => {"bar":[2],"bax":1,"bay":1,"baz":[10,20,30]}
Return Value
Key | Description |
|---|---|
Return value any | A modified object or Returned: always |
Collection links
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/projects/ansible/latest/collections/community/general/json_patch_recipe_filter.html