Get data from a json response

Hallo All,

i have following response and want to write the “session-id” into a variable for further using.

{
"id": 1,
"result": {
                "result": true,
                "mail": "[email protected]",
                "session-id": "xyz"
                 }
}

My Test script is:

let jsonData = pm.response.json();
console.log('All keys: ' + Object.keys(jsonData.result));
console.log(jsonData.result.mail);
console.log(jsonData.session-id);

In the console i can read all keys and the last line gives in the console:

“ReferenceError: id is not defined”

What can I do to get the session-id from the json?

Greetings Lutz

Hey @lutz.haseloff :wave:

Welcome to the Postman community :postman:

As the property has a - within the name, you would need to use bracket notation.

console.log(jsonData["session-id"])

Thanks!
Stupid me.
Works now.

Not stupid, we’ve all been there and no one knows everything straight away. :pray:t2:

Glad to see you have it working :heart:

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