cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JSON parse with http monitor

jimmy
Observer

Hello 

I would like to parse a json file with an http monitor this is my json

{ "services": [ { "available": true, "operation": "Communes", "responsecode": 200, "service": "Commune Service" }, { "available": true, "operation": "Annexe Groupe", "responsecode": 200, "service": "Documents Service" }, { "available": false, "operation": "Obtenir Disponibilité", "responsecode": 500, "service": "Utilisateurs Service" }, { "available": true, "operation": "Verifier Cheque", "responsecode": 200, "service": "Platefor" }, { "available": true, "operation": "Personne", "responsecode": 200, "service": "Personne" }, { "available": true, "operation": "Recherche", "responsecode": 200, "service": "Contrat" } ] } 

 

I would like to know how I could get the status
"available": true,

and make a warning if is set by false

 

 

thx for help ! 

3 REPLIES 3

HannahM
Dynatrace Champion
Dynatrace Champion

Is it a specific service you are interested in or do you need to know for each service?

Hi thx for answer me ! 

Is for each service 

HannahM
Dynatrace Champion
Dynatrace Champion

You can get the response and parse as json like this: 

var responseBody = response.getResponseBody();
var jsonData = JSON.parse(responseBody);

You will then need to iterate through each service checking for the status. You can then either use api.fail() directly to fail the monitor as soon as you find a service that is not available or you can set a variable and then check it once you have checked all the services and then fail the monitor with a message that states which services were not available.