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 10.4.0).
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
none
value 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 |
---|---|
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 |
---|---|
A list of JSON patch operations to apply. |
|
The source location for the copy and move operation. Mandatory for |
|
JSON Pointer path to the target location (see RFC 6901). |
|
Value to use in the operation. Ignored for |
|
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 |
---|---|
A modified object or Returned: always |