How to: Submit one or more sets of JSON data dependent on scenario?

Not sure if my title has explained this properly so I will use an example.

Say you have an endpoint where you have the option of submitting one or multiple classes such as:

[
  {
    "courseNbr": 1234,
    "isDeleted": false,
    "prefOrder": 1
  },
  {
    "courseNbr": 345,
    "isDeleted": false,
    "prefOrder": 2
  }
]

However, I’m using data files to pass the course information. Sometimes I want to submit one course and other times I want to submit more then that.

Does anyone know of a way I could perhaps use a pre-request script to check the amount of items inside the JSON data file and then submit that as part of the Body?

Why do you need to check how many items there are?

If the property is an array, it is totally acceptable to pass in a single item.

Are there other properties that need to be set accordingly?

Hi Allen,

Because the way I submit the data is like this:

[
{
“courseNbr”: {{courseNbr}},
“isDeleted”: {{isDeleted}},
“prefOrder”: {{prefOrder}}
}
]

{{}} being the variables for the data file. But if I want to add two or more items, it will only detect the first course.

I did figure out a way to send the data from a pre request script to the body, however I am having trouble formatting the data.