简体   繁体   中英

How to import nested JSON data into Postman's collection runner?

I have the following 'nested JSON' data:

[{  
   "method":"POST",
   "endpoint":"/users",
   "body":{  
      "username":"ZStGQoTVGvtBO",
      "role":"DEVICE_ADMINISTRATOR"
   },
   "res_code":400,
   "auth":[  
      "4565786",
      "bncfgnjfgnjgt"
   ]
}] 

How to import it into Postman collection runner? I am able to import simple JSON data but not nested JSON. And also there seems to be a problem in importing the "auth" element sometimes it's ignoring the "auth" element, sometimes it's just importing the second value of "auth" only.

You can do it manually in pre-request script:

pm.variables.set("username", data.body.username);//<- acess to nested value, you can't use {{body.username}}

or if you want to input some part of your data to request body you can:

pm.variables.set("bodyPart", JSON.stringify(data.someobject))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM