Powershell: `Test-Json` fails to parse schema while other validators succeed

Created on 8 May 2019  Â·  8Comments  Â·  Source: PowerShell/PowerShell

Steps to reproduce

good.params.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "0.0.0.1",
  "parameters": {
    "var1": {
      "value": "4"
    },
    "var2": {
      "reference": {
        "keyVault": {
          "id": "<keyvault-resource-id>"
        },
        "secretName": "<secret-name>"
      }
    }
  }
}
$json = Get-Content $PSScriptRoot\good.params.json -Raw
$schemaUri = ($json | ConvertFrom-Json).'$schema' -replace "#.*"
[string]$schema = Invoke-WebRequest $schemaUri
Test-Json -Json $json -Schema $schema

Expected behavior

I have tested the schema and json in two online validators and neither had issues, so I would expect Test-Json to not throw an error.

Actual behavior

Test-Json : Cannot parse the JSON schema.
At /bugrepro.ps1:4 char:1
+ Test-Json -Json $json -Schema $schema
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (:) [Test-Json], Exception
+ FullyQualifiedErrorId : InvalidJsonSchema,Microsoft.PowerShell.Commands.TestJsonCommand

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Darwin 18.5.0 Darwin Kernel Version 18.5.…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Question Resolution-External

Most helpful comment

@PowerShellTeam , considering

  • the NJsonSchema bug basically renders this cmdlet useless
  • the NJsonSchema bug is very stale with no recent responses from their team
  • PowerShell already contains references to Newtonsoft

Would you consider updating this cmdlet to use Json.NET instead of NJsonSchema?

All 8 comments

It looks like this is a bug with NJsonSchema as they currently have this issue: https://github.com/RicoSuter/NJsonSchema/issues/588

What other validators did you use that succeeded?

I used a few different random ones to validate. Is there any known workaround?

I was working on a CI process that validates ARM templates yesterday evening and I also encountered this issue.

@PowerShellTeam , considering

  • the NJsonSchema bug basically renders this cmdlet useless
  • the NJsonSchema bug is very stale with no recent responses from their team
  • PowerShell already contains references to Newtonsoft

Would you consider updating this cmdlet to use Json.NET instead of NJsonSchema?

This really needs to be fixed regardless of the "external" dependencies. You offer a service which includes choices made on libraries you use. If the library doesn't work anymore, then you need to respond and fix it in another way. @chriskuech seems to have an option which could help.

Anyщтн could contribute to NJsonSchema.

FYI, the issue at NJsonSchema (https://github.com/RicoSuter/NJsonSchema/issues/588) has been fixed.

We will get this with follow NJsonSchema release.

Was this page helpful?
0 / 5 - 0 ratings