PrivateFunctions/Validate-EntityJsonFile.ps1

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 
}