Nested JSON object despair

Hey all, I have the ultimate honor of testing/debugging an API that answers with some kind of json structure, example below:

    "m2m:ae": {
        "rn": "CAE1c8f40f0-56bb-48b7-8dd4-0f64ee1767e0",
        "pi": "cse-test",
        "ri": "/cse-test/cae4d7c0cdb-08ad-4e48-af32-38128e37b066",
        "api": "Lightman",
        "lbl": [
            "Manually registered endpoint"
        "ty": 2,
        "ct": "20201102T110311",
        "rr": "false",
        "poa": [

And now I’m stuck trying to access eg the value of “ri”, and have no clue how to reference the m2m:ae-part… I tried

postman.setEnvironmentVariable("id", jsonData.m2m.ri);
postman.setEnvironmentVariable("id", jsonData.m2m{"ae"}.ri);

and alike, but to no avail… Even Auntie Google won’t help me with named nested json objects… :frowning:

Hey @snaeqe

Welcome to the Postman community! :rocket:

It looks like something like this would be needed here:

pm.environment.set("id", jsonData["m2m:ae"].ri);

Some more details about the difference between dot and bracket notation and when to use it:


Thanks for the warm welcome, and that really solved the problem :smiling_face_with_three_hearts:

1 Like