Hi Guys. Is there any way to view HtmlWebResponseObject output in a screen-readable format?
I’m building a script and have to work with Rest API and right now just want to be able to view the response in a clean way (on screen).
It’s only for testing purposes, but currently, everything is nested and I have to dig through it each time.
I’m using this (although really I would like to be selecting * so I can see the response code as well as all the content, but that was just giving me one more step).
Invoke-WebRequest -Uri $URI -Method POST -Body $postparams | Select content
I tried piping to format-list and its a bit better but still not readable.
Does anyone have a tip for me? Initially, I thought I could just pipe it to convertto-json and get a plain text output but it’s not formatted so that doesn’t help
As a workaround right now I am putting each block into a $var and calling it like this $var.content
That should get you a PSObject. Keep in mind that JSON is typically a nested object, so you’ll need to most likely do some parsing work to get exactly what you need, but now that it’s a PSObject, you can use simple dot notation to get what you need (e.g. $result.api.response.result)
Hi Rob. I’m just converting back to JSON so that I can get my format in an easy to read format while I’m testing… When it’s in a PSobject, then as you said I have to dot it out but that is tricky when i don’t know what i need yet. Converting to JSON with the -depth option allows me to just see plain text on the screen like this.
{
"API": {
"response": {
"operation": {
"result": {
"message": "Field or column name is not found.",
"status": "Invalid column(s) specified.",
"statuscode": 3025
},
"name": "read"
}
},
"version": 1
}
}