# Put multiple JSON output values into a string

**URL:** <https://community.postman.com/t/put-multiple-json-output-values-into-a-string/73468>\
**Category:** Help Hub\
**Tags:** variables, json, string\
**Created:** [January 7, 2025, 5:05pm UTC](https://community.postman.com/t/put-multiple-json-output-values-into-a-string/73468 "2025-01-07T17:05:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![theboulderguy](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@theboulderguy](https://community.postman.com/u/theboulderguy)\
**Post date:** [January 7, 2025, 5:05pm UTC](https://community.postman.com/t/put-multiple-json-output-values-into-a-string/73468/1 "2025-01-07T17:05:15Z")

</div>

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):**

```auto
{
    "@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:**

```auto
// 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!!

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 7, 2025, 6:18pm UTC](https://community.postman.com/t/put-multiple-json-output-values-into-a-string/73468/2 "2025-01-07T18:18:17Z")

</div>

Hey @theboulderguy 👋

Welcome to the Postman Community :postman:

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

> [@Store IDs from json and re-use them in a second API call](https://community.postman.com/t/store-ids-from-json-and-re-use-them-in-a-second-api-call/5485/2):
>
> Hi @francoisc, Welcome to the community wave You can make use of Postman’s variables and collections for this. Create a collection with your two requests ([https://learning.getpostman.com/docs/postman/collections/intro\_to\_collections/](https://learning.getpostman.com/docs/postman/collections/intro_to_collections/)) In your first request’s test script, you can have the following snippet. let response = pm.response.json(), ids = \_.map(response.items, ({ id }) =\> ( id )); // This will store your ids in an array. For reference (https://lodash.com/docs/4.17.11#map) pm.v…

---

<div class="post-metadata">

**Author:** ![theboulderguy](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@theboulderguy](https://community.postman.com/u/theboulderguy)\
**Post date:** [January 8, 2025, 8:32am UTC](https://community.postman.com/t/put-multiple-json-output-values-into-a-string/73468/3 "2025-01-08T08:32:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [January 15, 2025, 8:33am UTC](https://community.postman.com/t/put-multiple-json-output-values-into-a-string/73468/4 "2025-01-15T08:33:06Z")

</div>

Closed on January 15, 2025, 8:33am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
