I have to get the values from JSON file for my test report purpose.
Can anyone help me how get values of passes, failure from the below JSON data.
{
"stats": {
"suites": 2,
"tests": 4,
"passes": 3,
"pending": 0,
"failures": 0,
"start": "2021-11-05T15:58:26.817Z",
"end": "2021-11-05T15:59:26.701Z",
"duration": 55162,
"testsRegistered": 4,
"passPercent": 75,
"pendingPercent": 0,
"other": 0,
"hasOther": false,
"skipped": 1,
"hasSkipped": true
},
}
I have tried below code, but not getting correct result
$json= Get-Content -Raw -Path 'C:\report.json' | ConvertFrom-Json
write-host "passes : $($json.passes)"
write-host "failures : $($json.failures)"
Result:
$json= Get-Content -Raw -Path 'C:\report.json' | ConvertFrom-Json
write-host "passes : $($json.passes)"
write-host "failures : $($json.failures)"
passes :
failures :
Edit: I have got the solution by adding below code
$json= Get-Content -Raw -Path 'C:\report.json' | ConvertFrom-Json
write-host "passes : $($json.stats.passes)"
write-host "failures : $($json.stats.failures)"