Parse JSON Postman response

前端 未结 3 1621
耶瑟儿~
耶瑟儿~ 2021-01-05 10:23

I have a test in Postman where I do a post request and need to parse the json response

The response looks like this:

\"aPIProxy\" : [ {
    \"name\"          


        
3条回答
  •  独厮守ぢ
    2021-01-05 11:21

    You could capture multiple 'name' properties using the _.map() function of Lodash, which is a built it module on the native application. I've had to modify what you need slightly as the name key would have been a duplicate.

    const result = _.map(pm.response.json().aPIProxy, data => ({
      name: data.name,
      revisionName: data.revision[0].name
    }))
    
    pm.environment.set("response", JSON.stringify(result))
    

    This would then store all the values in an environment variable for you to use elsewhere in another request.

提交回复
热议问题