How to run multiple request from runner taking input from .json file and also skip the request based condition based in the pre-request script body

I am trying to run thses apis and the data in the apis are in the format

{
        "condition":{
            "scenario": "success",
            "api": "/api/rest/2.0/users/create"
        },
        "data":{
            "name": "abcdef",
            "display_name": "abcdef_abcdef",
            "password": "Abcd@2023",
            "email": "[email protected]"
        }
    }

similar to this

This is the image of the pre-request script
Screenshot 2023-06-15 at 11.49.26 AM

This is the pre-request script to check condition.
Screenshot 2023-06-15 at 11.50.43 AM

The error I am getting is
Screenshot 2023-06-15 at 11.51.55 AM

These are the apis I’m trying to run from runner

There are two ways to accessing data from JSON or CSV files.

Postman JavaScript reference | using-data-variables-in-scripts

Using CSV and JSON Data Files in the Postman Collection Runner | Postman Blog

It looks like you are converting what is already an object, so I’m not sure toObject is needed.

The error is saying its reading the variable as [object Object] instead of the first character being a { like its meant to be. Therefore the error is correct. The β€˜o’ is unexpected and the wrong type.

I prefer method two which is to access the elements using the special β€œdata” dictionary.

data.condition.api or data[β€œcondition”][β€œapi”]

If you console log data on its own as the first line in your pre-request script, it should already be an object that you can work with.

// try it yourself
console.log(data);