# JSON Array in POST Body

**URL:** <https://community.postman.com/t/json-array-in-post-body/5233>\
**Category:** Help Hub\
**Created:** [May 1, 2019, 2:46am UTC](https://community.postman.com/t/json-array-in-post-body/5233 "2019-05-01T02:46:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lynchbradley](https://avatars.discourse-cdn.com/v4/letter/l/c4cdca/32.png) [@lynchbradley](https://community.postman.com/u/lynchbradley)\
**Post date:** [May 1, 2019, 2:46am UTC](https://community.postman.com/t/json-array-in-post-body/5233/1 "2019-05-01T02:46:14Z")

</div>

Hello-  
I have multiple line items that i’m trying to post. During the GET request, each line item field is stored as a global variable.  
The problem is that sometimes I have one line item only that I want to post and then the next run of the request I could have two line items that I want to post.

How do I create an ‘if’ conditional statement in order to only grab the stored variables that are associated to the number of line items.

i.e

```
"line_items" : [
{
	"title" : "{{product_Name1}}" ,
	"variant_title" : "{{product_desc1}}" ,
	"description" : "{{product_desc1}}" ,
	"Quantity" : "{{product_Count1}}" ,
	"amount" : "{{product_price11}}" ,
	"total_price" : "{{product_price11}}" ,
	"currency" : "{{product_unit1}}" ,
	"weight" : 3 ,
	"weight_unit" : "oz" 
}

```

,

if ("{{purchasedItemsCount}}" \> 1)  
{  
“title” : “{{product\_Name2}}” ,  
“variant\_title” : “{{product\_desc2}}” ,  
“description” : “{{product\_desc2}}” ,  
“Quantity” : “{{product\_Count2}}” ,  
“amount” : “{{product\_price22}}” ,  
“total\_price” : “{{product\_price22}}” ,  
“currency” : “{{product\_unit2}}” ,  
“weight” : 3 ,  
“weight\_unit” : “oz”  
}  
]

---

<div class="post-metadata">

**Author:** ![tmccann](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tmccann/32/3550_2.png) [@tmccann](https://community.postman.com/u/tmccann)\
**Post date:** [May 1, 2019, 12:34pm UTC](https://community.postman.com/t/json-array-in-post-body/5233/2 "2019-05-01T12:34:06Z")

</div>

@lynchbradley To do something like this, you would likely want to put this logic in the `Pre-Request` tab of your call.

Then you would have it do this conditional check and set values as needed to be used in the call.  
You can also do this logic in the `Test` tab if it makes sense to do it there.
