ansible-jsonpatch icon indicating copy to clipboard operation
ansible-jsonpatch copied to clipboard

How to add object with multiple values into array

Open OndrosI opened this issue 2 years ago • 0 comments

Hello, i have this json

{
  "repositories": [
    { 
      "name": "some-name", 
      "type": "vcs", 
      "url": "[email protected]" 
    }
  ]
}

and i am trying to create this

{
  "repositories": [
    { 
      "name": "some-name", 
      "type": "vcs", 
      "url": "[email protected]" 
    },
    { 
      "name": "new-value", 
      "type": "vcs", 
      "url": "[email protected]" 
    }
  ]
}

but i dont know how. Is there possibility add multiple values into object?

like this:

- name: append key/values
  json_patch:
    src: /file.json
    operations:
      - op: add
        path: '/repositories/-'
        value: 
          name: "new-value"
          type: "vcs"
          url: "[email protected]"
    pretty: yes
    create: yes

OndrosI avatar Aug 03 '22 10:08 OndrosI