Powershell: Test-Json cmdlet (JSON lint/validator)

Created on 11 Jul 2017  路  2Comments  路  Source: PowerShell/PowerShell

Placeholder for now as I follow up on some customer scenarios: it would be really nice to have a cmdlet that could validate JSON before it's used as input. I'd expect for something like this to already exist in Newtonsoft.Json.

IMHO, it's a nice-to-have for 6.0.0 depending on how we're looking with HighPriority over the next couple months. If not, we could move it out to 6.1.0 without a real problem.

Also, this would require an RFC.

Issue-Enhancement Resolution-Fixed

Most helpful comment

Along these lines, how about a Test-Xml / Format-Xml set of cmdlets? These are implemented in PSCX in C# and could probably be ported over now that .NET Core 2 has support for XML Schema. The Test-Xml cmdlet's utility is fairly self-evident but perhaps that is less so with Format-Xml. The latter command is very handy when you have an XML file that is a single line and 4000 chars wide. :-) It is also handy when attributes are scattered about. A formatter can also put attributes on a new line. In general it makes the XML output easier to read e.g.:

gc foo.xml
<?xml version="1.0"?><doc><assembly><name>VBFormsApp</name></assembly><members></members></doc>

becomes:

format-xml foo.xml
<?xml version="1.0"?>
<doc>
  <assembly>
    <name>VBFormsApp</name>
  </assembly>
  <members></members>
</doc>

All 2 comments

Along these lines, how about a Test-Xml / Format-Xml set of cmdlets? These are implemented in PSCX in C# and could probably be ported over now that .NET Core 2 has support for XML Schema. The Test-Xml cmdlet's utility is fairly self-evident but perhaps that is less so with Format-Xml. The latter command is very handy when you have an XML file that is a single line and 4000 chars wide. :-) It is also handy when attributes are scattered about. A formatter can also put attributes on a new line. In general it makes the XML output easier to read e.g.:

gc foo.xml
<?xml version="1.0"?><doc><assembly><name>VBFormsApp</name></assembly><members></members></doc>

becomes:

format-xml foo.xml
<?xml version="1.0"?>
<doc>
  <assembly>
    <name>VBFormsApp</name>
  </assembly>
  <members></members>
</doc>

I would also love to see a Test-Json, Test-XML, and Format-XML as part of baseline Powershell. Looks like the Test-Json is well underway

Was this page helpful?
0 / 5 - 0 ratings