# Extract data into globalvariable

**URL:** <https://community.postman.com/t/extract-data-into-globalvariable/44646>\
**Category:** Help Hub\
**Tags:** variables, json\
**Created:** [March 2, 2023, 9:01am UTC](https://community.postman.com/t/extract-data-into-globalvariable/44646 "2023-03-02T09:01:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![claus-borgquist](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@claus-borgquist](https://community.postman.com/u/claus-borgquist)\
**Post date:** [March 2, 2023, 9:01am UTC](https://community.postman.com/t/extract-data-into-globalvariable/44646/1 "2023-03-02T09:01:04Z")

</div>

I want to extract the value 0dad692e-e256-4030-95b7-bda85d0ab4d8 from this response into a global variable, how do i do that?

[  
{  
“eventTime”: “2023-03-02T08:44:01.489Z”,  
“recordTime”: “2023-03-02T07:44:02.168Z”,  
“eventTimeZoneOffset”: “+01:00”,  
“baseExtension”: null,  
“otherAttributes”: {},  
“bizStep”: “urn:epcglobal:cbv:bizstep:packing”,  
“readPoint”: null,  
“parentID”: “00357072944000271034”,  
“childEPCs”: {  
“epc”: [  
{  
“value”: “0104030700134336211223039122485001”  
}  
]  
},  
“action”: “ADD”,  
“disposition”: “urn:epcglobal:cbv:disp:in\_progress”,  
“bizLocation”: {  
“id”: “urn:epc:id:sgln:579000205241…1”,  
“extension”: null,  
“any”:   
},  
“extension”: null,  
“any”: ,  
“eventType”: “AGGREGATION\_EVENT”,  
“anyFcc”: [  
{  
“children”: ,  
“name”: “urn:atos:extension:xsd:market”,  
“value”: “DE”,  
“attributes”: {},  
“type”: “STRING”  
},  
{  
“children”: ,  
“name”: “urn:atos:extension:xsd:bizCountry”,  
“value”: “DK”,  
“attributes”: {},  
“type”: “STRING”  
},  
{  
“children”: ,  
“name”: “urn:saga:extension:xsd:originalDocumentId”,  
“value”: “0dad692e-e256-4030-95b7-bda85d0ab4d8”,  
“attributes”: {},  
“type”: “STRING”  
}  
],  
“bizLocExFcc”: ,  
“bizLocAnyFcc”: ,  
“readPointExFcc”: ,  
“readPointAnyFcc”: ,  
“errorDeclarationAnyFcc”: ,  
“eventId”: “00086f80-b8ce-11ed-99dd-4f3689df236f”,  
“partitionKey”: 1677740400206,  
“numberOfChildNodes”: 0,  
“exFcc”:   
}  
]

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [March 2, 2023, 12:26pm UTC](https://community.postman.com/t/extract-data-into-globalvariable/44646/2 "2023-03-02T12:26:59Z")

</div>

Why a global variable, are you really sure you want this value available to all workspaces and collections in Postman? I would recommend a Collection or Environment variable.

This is how to directly target the element.

```auto
let response = pm.response.json()
console.log(response[0].anyFcc[2].value);

```

Your response is an array, although it only appears to have one element.

Array indexes start at zero, so its response[0].

Your field is under the anyFcc element, which is also an array.

```auto
"anyFcc": [
    {
        "children": [],
        "name": "urn:atos:extension:xsd:market",
        "value": "DE",
        "attributes": {},
        "type": "STRING"
    },
    {
        "children": [],
        "name": "urn:atos:extension:xsd:bizCountry",
        "value": "DK",
        "attributes": {},
        "type": "STRING"
    },
    {
        "children": [],
        "name": "urn:saga:extension:xsd:originalDocumentId",
        "value": "0dad692e-e256-4030-95b7-bda85d0ab4d8",
        "attributes": {},
        "type": "STRING"
    }
],

```

It’s the the third element in that array in the value field, so its ‘anyFcc[2].value’.

This may be brittle, and will fail if the children aren’t returned consistently.

You may need to search for “DocumentId” in the name instead.

One way to do this.

```auto
console.log(response[0].anyFcc.find(element => {return element.name.includes('DocumentId')}).value);

```

How to assign to variables?

This is a core Postman concept. I would recommend you go through the basics in the Learning Centre first.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/c/ac5b16484139d3574e40a2b116a8d61fac55480b.png)

In particular the ‘APIs 101’ and ‘Testing and Automation courses’.

You can read more here about variables.

[Using variables | Postman Learning Center](https://learning.postman.com/docs/sending-requests/variables/#sharing-and-persisting-data)

Please remember to use the preformatted text option in the editor when posting code or JSON responses, as its stops all the text being aligned to the left.

---

<div class="post-metadata">

**Author:** ![claus-borgquist](https://avatars.discourse-cdn.com/v4/letter/c/b2d939/32.png) [@claus-borgquist](https://community.postman.com/u/claus-borgquist)\
**Post date:** [March 2, 2023, 12:52pm UTC](https://community.postman.com/t/extract-data-into-globalvariable/44646/3 "2023-03-02T12:52:42Z")

</div>

Thank you, that was exactly what i needed.
