Skip to content

Test-Json fails with UnresolvedJsonSchemaRef when "$schema" is http://json-schema.org/schema (regression in 7.6.7, 7.5.12, 7.4.21) #28245

Closed

Description

@Agger1995

Prerequisites

Steps to reproduce

Since 7.6.7, 7.5.12 and 7.4.21, Test-Json can't use a schema whose $schema keyword is http://json-schema.org/schema. It writes UnresolvedJsonSchemaRef and returns False for any input, valid or not. With -ErrorAction SilentlyContinue, that False comes back with no output at all. Up to 7.6.6, 7.5.11 and 7.4.20 it validated the input normally.

# A concrete metaschema URI works in every version
Test-Json -Json '{}' -Schema '{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object" }'

# The http://json-schema.org/schema URI at the top level
Test-Json -Json '{}' -Schema '{ "$schema": "http://json-schema.org/schema", "type": "object" }'

# The same URI in a nested subschema, even though the input doesn't contain "a"
Test-Json -Json '{}' -Schema '{ "type": "object", "properties": { "a": { "$schema": "http://json-schema.org/schema" } } }'

-SchemaFile behaves the same as -Schema.

Notes:

  • The schemas contain no $ref. Get-Error shows the failure happens while resolving the $schema dialect (Json.Schema.SchemaRegistry.SetDialect), so the message about external references is misleading here.
  • Any $schema value other than the exact draft-06, draft-07, 2019-09 and 2020-12 metaschema URIs fails the same way. That includes common variants such as https://json-schema.org/schema and the http spelling of the 2020-12 URI, http://json-schema.org/draft/2020-12/schema. All of them work on 7.6.6.
  • Passing -FetchExternalReference restores the old result (last command under "Actual behavior"), because the metaschema is then downloaded again. Earlier versions apparently did that download implicitly.
  • None of the release notes for v7.6.7, v7.5.12 and v7.4.21 mentions this change.

Could any of these be considered?

  1. Make the error say that the $schema metaschema could not be resolved, rather than referring to external references.
  2. Mention the change as a breaking change in the release notes.
  3. Resolve the json-schema.org metaschema URIs, including http://json-schema.org/schema, without a network fetch.

Related: #28205 (and #28214, closed as its duplicate), and #28218 (a separate 7.6.7 Test-Json regression from the same servicing change).

Expected behavior

PS> Test-Json -Json '{}' -Schema '{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object" }'
True
PS> Test-Json -Json '{}' -Schema '{ "$schema": "http://json-schema.org/schema", "type": "object" }'
True
PS> Test-Json -Json '{}' -Schema '{ "type": "object", "properties": { "a": { "$schema": "http://json-schema.org/schema" } } }'
True

Actual behavior

PS> Test-Json -Json '{}' -Schema '{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object" }'
True
PS> Test-Json -Json '{}' -Schema '{ "$schema": "http://json-schema.org/schema", "type": "object" }'
Test-Json: The JSON schema contains a reference that could not be resolved. External schema references are not supported by default, use the 'FetchExternalReference' parameter to enable it.
False
PS> Test-Json -Json '{}' -Schema '{ "type": "object", "properties": { "a": { "$schema": "http://json-schema.org/schema" } } }'
Test-Json: The JSON schema contains a reference that could not be resolved. External schema references are not supported by default, use the 'FetchExternalReference' parameter to enable it.
False
PS> Test-Json -Json '{}' -Schema '{ "$schema": "http://json-schema.org/schema", "type": "object" }' -FetchExternalReference
True

Error details

PS> Get-Error

Exception             :
    Type           : System.Exception
    Message        : The JSON schema contains a reference that could not be resolved. External schema references are not supported by default, use the 'FetchExternalReference' parameter to enable it.
    InnerException :
        Type       : Json.Schema.RefResolutionException
        BaseUri    : http://json-schema.org/schema
        TargetSite :
            Name          : SetDialect
            DeclaringType : [Json.Schema.SchemaRegistry]
            MemberType    : Method
            Module        : JsonSchema.Net.dll
        Message    : Could not resolve 'http://json-schema.org/schema'
        Source     : JsonSchema.Net
        HResult    : -2146233088
        StackTrace :
   at Json.Schema.SchemaRegistry.SetDialect(JsonSchema schema, Vocabulary[] parentDialect)
   at Json.Schema.SchemaRegistry.Scan(Uri baseUri, JsonSchema document)
   at Json.Schema.SchemaRegistry.RegisterSchema(Uri uri, IBaseDocument document)
   at Json.Schema.JsonSchema.Evaluate(JsonNode root, EvaluationOptions options)
   at Microsoft.PowerShell.Commands.TestJsonCommand.ProcessRecord()
    HResult        : -2146233088
TargetObject          : Json.Schema.JsonSchema
CategoryInfo          : InvalidData: (Json.Schema.JsonSchema:JsonSchema) [Test-Json], Exception
FullyQualifiedErrorId : UnresolvedJsonSchemaRef,Microsoft.PowerShell.Commands.TestJsonCommand
InvocationInfo        :
    MyCommand        : Test-Json
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 1
    Line             : Test-Json -Json '{}' -Schema '{ "$schema": "http://json-schema.org/schema", "type": "object" }'
    Statement        : Test-Json -Json '{}' -Schema '{ "$schema": "http://json-schema.org/schema", "type": "object" }'
    PositionMessage  : At line:1 char:1
                       + Test-Json -Json '{}' -Schema '{ "$schema": "http://json-schema.org/sc …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Test-Json
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
      0
      1

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.7
PSEdition                      Core
GitCommitId                    7.6.7
OS                             Ubuntu 24.04.2 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. mklement0 commented on Oct 22, 2026

    @mklement0
    Contributor

    FWIW, while the problem still exists in the current stable version, v7.6.7, it no longer does in the current preview version, v7.7.0-preview.5.

  2. daxian-dbw commented on Oct 28, 2026

    @daxian-dbw
    Member

    Fixed by #28273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions