Quick JSON validation

Sometimes I get a JSON file or payload and I want to quickly check whether it's valid, at least from a syntax persective (the much maligned XML has had schema validation for a very long time, but that's a rant for some other day).

A quick search will show a whole bunch of options for doing this. This one is the one I happened to use today.

PS > $foo = [System.IO.File]::ReadAllText("c:\myfile.json")
PS > $foo
{
  "Comment":"this is my file",
  "Value":true
}

PS > ConvertFrom-Json $foo
Comment    : this is my file
Value      : True

Enjoy!

Tags:  powershell

Home