Adding multiple line items to a JSON request

Hi All,
I know this out of the scope of support but was hoping someone out there might help.
I am using a pipe to create an invoice in Shopify. Shopify has an array called line_items and you add your qty and the product. This works for one product but what if I have 3, or 4, etc. I can’t send a qty of 0.
Since the pipe request looks like this:
{“draft_order”:{“line_items”:[{“variant_id”:“{item}”,“quantity”:“{qty}”}],“note”:“{on}”,“customer”:{“id”:“{customer}”},“use_customer_default_address”:true}}

You can see the line_items array. I know that I can just add another element to that array but I don’t always have that. Sometimes customers have other items and I’d like a conditional I guess.
Something like:
If service fee is not blank, add another line_item element making the JSON request look like:
{“draft_order”:{“line_items”:[{“variant_id”:“{item}”,“quantity”:“{qty}”},{“variant_id”:“{item2}”,“quantity”:“{qty2}”}],“note”:“{on}”,“customer”:{“id”:“{customer}”},“use_customer_default_address”:true}}

Notice that the above has a second element within the line_items array. This seems complicated as I type this out but very popular considering most invoices have line items and we never know how many there will be. It is a variable and we just tacking one on to the arrays we send.
Any ideas?

How are you getting each line item? Are they coming from another table? Or theres essentially just a few choice of products within the form?

Hi Moe,

They are just fields. All within the same table. So my parameters I send are all within the table. Sometimes they have a value, sometimes not. So a record might be:
1,pants,2,shirt
And other times it might be:
1,pants
So line_item[0] is qty and id of that product.
line_item[1] is qty and id of another product.