PrivateFunctions/Validate-EntityJsonFile.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
Function Validate-EntityJsonFile { [OutputType([Boolean])] [CmdletBinding()] Param( [String] $EntityJsonFile ) If (-not(Test-Path -Path $EntityJsonFile -PathType Leaf)) { Write-Host "Het bestand '$($EntityJsonFile)' kon niet worden gevonden." Return $False; } $EntityJsonRaw = Get-Content $EntityJsonFile -Raw -ErrorAction Ignore if (!$EntityJsonRaw) { Write-Error "Fout ontstaan bij inlezen van bestand '$($EntityJsonFile)'." Return; } Write-Verbose "Validatie voor geldige JSON..." Try { $EntityJsonObject = $EntityJsonRaw | ConvertFrom-Json } Catch { Write-Host "Opgegeven bestand '$($EntityJsonFile)' bevat geen geldige JSON. Gebruik bij twijfel een JSON validator (bijv. https://jsonlint.com/) om je JSON bestand te controleren." -ForegroundColor Red Return $False; } If (-not($EntityJsonObject.PSobject.Properties.name -match "entities") -or $EntityJsonObject.entities.Count -eq 0) { Write-Host "Opgegeven bestand '$($EntityJsonFile)' bevat geen entiteiten of deze is leeg." -ForegroundColor Red Return $False; } Write-Verbose "JSON validatie voltooid." Return $True } |