Put multiple JSON output values into a string

So… it seems I am stuck and in need of some help due to my basic skill-set in Java and Json.
Thanks in advanced!!

What I want to do:
My output data (JSON-format) contains multiple employee_id’s. Each employee has a different id-value which i want to put into a single string and have it set as global/collection variable so that i can use it in some other requests.

The output data (example):

{
    "@odata.context": "https://link******",
    "value": [
        {
            "employee_id": 2906,
            "employee_code": "PM_1",
        },
        {
            "employee_id": 2907,
            "employee_code": "PM_2"
        },
        {
            "employee_id": 2908,
            "employee_code": "PM_3"
        }
    ]
}

How I’d like to use it in a Post-Response script:

// in the Post-request script:
var employees = [2906, 2907, 2908] 
pm.globals.set("employees", employees);

// in a different pre-request script it'll then be used as:
var employees = pm.globals.get("employees");
pm.globals.set("randomEmployeeID", employees[Math.floor(Math.random() * employees.length)]);

My problem:
How to get the json output-values into this: [2906, 2907, 2908] ?

I hope someone is able to help me out, thanks again!!

Hey @theboulderguy :wave:

Welcome to the Postman Community :postman:

The code from this post could be adjusted and used for your scenario:

1 Like

Now that worked like a charm!!! Thanks for the redirect!

1 Like