# Splitting a List into chunks

**URL:** <https://forum.ansible.com/t/splitting-a-list-into-chunks/31206>\
**Category:** Ansible Project\
**Created:** [September 5, 2019, 2:15pm UTC](https://forum.ansible.com/t/splitting-a-list-into-chunks/31206 "2019-09-05T14:15:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spiro\_Mitsialis](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Spiro\_Mitsialis](https://forum.ansible.com/u/Spiro_Mitsialis)\
**Post date:** [September 5, 2019, 2:15pm UTC](https://forum.ansible.com/t/splitting-a-list-into-chunks/31206/1 "2019-09-05T14:15:37Z")

</div>

Hi,  
I have a list of 200+ items (showing sample below). I need to update a database with these records using the URI module. The backend API only supports 100 records at at time.  
How can I loop through the URI module with 100 records at a time. I was thinking of using json\_query and doing slicing as per the JMEPath docs but cant find any examples of the syntax for Ansible.  
If using the json\_quere, I would need some sort of variable in the slice.

`

- name: Add/Update switchport in cmdb  
uri:  
url: https://{{ cmdb }}/{{ switchports }}/batchUpsert  
method: PUT  
validate\_certs: no  
body\_format: json  
body: ‘{{ new\_list | json\_query([:100] }}’  
register: batchupsert\_result  
loop:???  
`

`

“new\_list”: [  
{

“description”: null,  
“id”: “cjzu47wi6000301yu0dse3q53”,  
“lastSeenDate”: “2019-09-05 10:06:42”,  
“mediaType”: “access”,  
“name”: “GigabitEthernet2/1/1”,  
“poeEnabledInd”: true,  
“portDuplexModeId”: “cjzodb84y001201fmbox90ygt”,  
“portFastInd”: true,  
“portSpeedId”: “cjzodk5zx001301fmac9u54oc”,  
“securityShutdownInd”: “false”,  
“status”: “down”,  
“voiceInd”: false  
},  
{  
“description”: null,  
“id”: “cjzu4jsq1000u01yu9cw4a9h7”,  
“lastSeenDate”: “2019-09-05 10:06:42”,  
“mediaType”: “access”,  
“name”: “GigabitEthernet2/0/9”,  
“poeEnabledInd”: true,  
“portDuplexModeId”: “cjzodb84y001201fmbox90ygt”,  
“portFastInd”: true,  
“portSpeedId”: “cjzodk5zx001301fmac9u54oc”,  
“securityShutdownInd”: “false”,  
“status”: “down”,  
“voiceInd”: false  
},  
{  
“description”: null,  
“id”: “cjzu4jxhc000v01yuf9c7atd3”,  
“lastSeenDate”: “2019-09-05 10:06:42”,  
“mediaType”: “access”,  
“name”: “TenGigabitEthernet2/1/3”,  
“poeEnabledInd”: true,  
“portDuplexModeId”: “cjzodb84y001201fmbox90ygt”,  
“portFastInd”: true,  
“portSpeedId”: “cjzodk5zx001301fmac9u54oc”,  
“securityShutdownInd”: “false”,  
“status”: “shutdown”,  
“voiceInd”: false  
},  
{  
“description”: null,  
“id”: “cjzu48c09000401yu1o443fuq”,  
“lastSeenDate”: “2019-09-05 10:06:42”,  
“mediaType”: “access”,  
“name”: “TenGigabitEthernet2/1/4”,  
“poeEnabledInd”: true,  
“portDuplexModeId”: “cjzodb84y001201fmbox90ygt”,  
“portFastInd”: true,  
“portSpeedId”: “cjzodk5zx001301fmac9u54oc”,  
“securityShutdownInd”: “false”,  
“status”: “down”,  
“voiceInd”: false  
}  
]

`
