# Append data to json file using ansible modules

**URL:** <https://forum.ansible.com/t/append-data-to-json-file-using-ansible-modules/32656>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [April 10, 2020, 7:01pm UTC](https://forum.ansible.com/t/append-data-to-json-file-using-ansible-modules/32656 "2020-04-10T19:01:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shyam.awk](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@shyam.awk](https://forum.ansible.com/u/shyam.awk)\
**Post date:** [April 10, 2020, 7:01pm UTC](https://forum.ansible.com/t/append-data-to-json-file-using-ansible-modules/32656/1 "2020-04-10T19:01:58Z")

</div>

Hi All,

Is it possible to update the data of json file using ansible modules.

I tried on windows machine using win\_lineinfile module but the required file is not updating.

The line is updating at the end of the file.

Can any one suggest the solution for editing fields in json file.

Thank you,

---

<div class="post-metadata">

**Author:** ![vinod93pop](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@vinod93pop](https://forum.ansible.com/u/vinod93pop)\
**Post date:** [April 10, 2020, 8:16pm UTC](https://forum.ansible.com/t/append-data-to-json-file-using-ansible-modules/32656/2 "2020-04-10T20:16:13Z")

</div>

You have a parameter insert before or insert after where you can regex and update your code. Let us know if it works. Or put your code and error to get it to work

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 10, 2020, 10:11pm UTC](https://forum.ansible.com/t/append-data-to-json-file-using-ansible-modules/32656/3 "2020-04-10T22:11:30Z")

</div>

It depends on your data.

Please post your json and tell what you want to manipulate exactly.  
Lineinfile sounds fragile. You might have better results with from\_json, combine, and to\_json.

---

<div class="post-metadata">

**Author:** ![Shyam](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@Shyam](https://forum.ansible.com/u/Shyam)\
**Post date:** [April 11, 2020, 7:15am UTC](https://forum.ansible.com/t/append-data-to-json-file-using-ansible-modules/32656/4 "2020-04-11T07:15:25Z")

</div>

Hi Vinod and dick,

Thank you, please look at the json file on the remote server. I’m trying to replace the nas path using win\_lineinfile, but the path that I’m providing is updating at the end of the file.

Hi dick, please update how to do with from\_json and to\_json.

Json file:

[  
{  
“Service\_id” : “node1”  
“Source\_path” : “\\192.168.1.1\data\nonprod”  
“Source\_type” : “NAS”  
“Deztination\_type”: “Nas”  
}  
]

Playbook:

Win\_lineinfile:  
Path: D:\dest\config.json  
regexp : ‘^source\_path’  
insertafter: ‘^service\_id’  
line: ‘\\192.168.1.2\data\nonprod’  
state: present

Thankyou,  
Shyam
