title: How to check if file has valid JSON syntax in Powershell
body: <p>I am trying to write a powershell script that reads a file and prints "true" if it is a valid JSON file. I am using Powershell v3.0 and this is what I have right now : </p>
  
  <pre><code>$text = Get-Content .\filename.txt -Raw 
  $powershellRepresentation = $text | ConvertFrom-Json
  </code></pre>
  
  <p>How do I check the return code? I mean I want something like this :</p>
  
  <pre><code>if(file not a JSON file){
   Write-Host "not JSON"
  }
  else{
   Write-Host "True"
  }
  </code></pre>