You could replace Invoke-WebRequest with Invoke-RestMethod which auto-converts json response to a psobject so you can use:
$response = Invoke-RestMethod -Uri "https://yadayada:8080/bla"
$response.flag
You could replace Invoke-WebRequest with Invoke-RestMethod which auto-converts json response to a psobject so you can use:
$response = Invoke-RestMethod -Uri "https://yadayada:8080/bla"
$response.flag