Skip to content

New version 7.4.0 doesn't handle JSON schema correctly #20743

@FormindGMO

Description

@FormindGMO

Prerequisites

Steps to reproduce

Get to latest 7.4.0 (or preview) version of Powershell
Create schema.json file as follows:

{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "http://lol.com/lol.json",
    "type": "object",
    "properties": {
        "lol": {
            "type": "integer"
        },
        "muth": {
            "type":"boolean"
        }
    },
    "required": [
        "lol","muth"
    ],
    "additionalProperties": false

}

Create a sample JSON file as follows:

{
  "lol": 4,
  "muth": false
}

Expected behavior

PS> Get-Content .\the.json -Raw | Test-Json -SchemaFile .\schema.json
True

Actual behavior

PS C:\Temp\toto> Get-Content .\the.json -Raw | Test-Json -SchemaFile .\schema.json
Test-Json: Cannot parse the JSON.
False

Error details

Exception             :
    Type           : System.Exception
    Message        : Cannot parse the JSON.
    InnerException :
        Type       : Json.Schema.JsonSchemaException
        TargetSite :
            Name          : DetermineSpecVersion
            DeclaringType : Json.Schema.JsonSchema
            MemberType    : Method
            Module        : JsonSchema.Net.dll
        Message    : Custom meta-schema `$schema` keywords must eventually resolve to a meta-schema for a supported
specification version.
        Source     : JsonSchema.Net
        HResult    : -2146233088
        StackTrace :
   at Json.Schema.JsonSchema.DetermineSpecVersion(JsonSchema schema, SchemaRegistry registry, SpecVersion desiredDraft)
   at Json.Schema.JsonSchema.Evaluate(JsonNode root, EvaluationOptions options)
   at Microsoft.PowerShell.Commands.TestJsonCommand.ProcessRecord()
    HResult        : -2146233088
TargetObject          : {
                        "lol": 4,
                        "muth": false
                        }                                                                                                                                                                                                                       CategoryInfo          : InvalidData: ({                                                                                                         "lol": 4,                                                                                                               "muth": false                                                                                                           }                                                                                                                       :String) [Test-Json], Exception                                                                 FullyQualifiedErrorId : InvalidJson,Microsoft.PowerShell.Commands.TestJsonCommand                                       InvocationInfo        :                                                                                                     MyCommand        : Test-Json                                                                                            ScriptLineNumber : 1                                                                                                    OffsetInLine     : 31                                                                                                   HistoryId        : 11                                                                                                   Line             : Get-Content .\the.json -Raw | Test-Json -SchemaFile .\schema.json                                    Statement        : Test-Json -SchemaFile .\schema.json                                                                  PositionMessage  : At line:1 char:31                                                                                                       + Get-Content .\the.json -Raw | Test-Json -SchemaFile .\schema.json                                                     +                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                  InvocationName   : Test-Json                                                                                            CommandOrigin    : Internal                                                                                         ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1                                                             PipelineIterationInfo :

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.0-rc.1
PSEdition                      Core
GitCommitId                    7.4.0-rc.1
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility moduleWG-NeedsReviewNeeds a review by the labeled Working Group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions