Skip to content

Test-Json in 7.6.7 writes no error for violations nested below the first level (e.g. array items) #28218

Closed

Description

Prerequisites

Steps to reproduce

This is a regression from 7.6.6 to 7.6.7. When a schema violation is nested deeper than one level (for example an array item), Test-Json still returns False, but it no longer writes an error that says what is wrong or where. Violations at the top level are still reported.

$schema = '{"type":"object","properties":{"top":{"type":"string"},"list":{"type":"array","items":{"type":"string","pattern":"^[a-z]+$"}}}}'

'{"top":1}' | Test-Json -Schema $schema -ErrorVariable e1 -ErrorAction SilentlyContinue
"errors: $($e1.Count)"; $e1 | % { "  $_" }

'{"list":["ok","NOT OK"]}' | Test-Json -Schema $schema -ErrorVariable e2 -ErrorAction SilentlyContinue
"errors: $($e2.Count)"; $e2 | % { "  $_" }

Expected behavior

PS 7.6.6
False
errors: 1
  The JSON is not valid with the schema: Value is "integer" but should be "string" at '/top'
False
errors: 1
  The JSON is not valid with the schema: The string value is not a match for the indicated regular expression at '/list/1'

Actual behavior

PS 7.6.7
False
errors: 1
  The JSON is not valid with the schema: Value is "integer" but should be "string" at '/top'
False
errors: 0

Error details

No error is written. That is the bug.

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.7
PSEdition                      Core
GitCommitId                    7.6.7
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

Likely cause: the 7.6.7 servicing change behind #28205 / #28214 ("Disable fetch delegate on $ref feature…") switched TestJsonCommand from OutputFormat.List to OutputFormat.Hierarchical without also backporting the recursive error reporting from master.

  • v7.6.6 evaluates with OutputFormat.List. That output is flat, so iterating evaluationResults.Details once reaches every error.
  • v7.6.7 evaluates with OutputFormat.Hierarchical (_evaluationOptions, line ~143), but ProcessRecord still calls HandleValidationErrors on the root and its direct Details only (lines ~287–295). Any error deeper than that, such as /list/1, is never written.
  • master also uses Hierarchical, but reports errors with a recursive ReportValidationErrors that descends into nestedResult.Details, so it does not have this problem.

Backporting the recursive ReportValidationErrors to release/v7.6 should fix it. It would also help to add a test that asserts an error is written for a nested or array-item violation.

Impact: scripts that use -ErrorVariable to show users why validation failed now get False with no details. We found this when our config-validation tests failed on the 7.6.7 upgrade.

Activity

  1. TaekeK commented on Oct 16, 2026

    @TaekeK

    The same regression also hits schema composition, not only nested instance locations. A failing if/then inside allOf writes no error on 7.6.7. At the top level it still does:

    $schemas = '{"if":{"required":["a"]},"then":{"required":["b"]}}',
               '{"allOf":[{"if":{"required":["a"]},"then":{"required":["b"]}}]}'
    foreach ($s in $schemas) {
        $e = $null
        $r = Test-Json -Json '{"a":1}' -Schema $s -ErrorVariable e -ErrorAction SilentlyContinue
        "returned $r, errors $(@($e).Count)"
    }
    PS 7.5.11            PS 7.6.7
    returned False, errors 1    returned False, errors 1
    returned False, errors 1    returned False, errors 0

    This breaks the common try { Test-Json ... -ErrorAction Stop } catch { invalid } pattern as well as -ErrorVariable. No exception is raised, so the document is treated as valid. The recursive reporting suggested above should cover this case too, since the allOf → then → required result sits two levels below the root.

  2. UncleBats commented on Oct 20, 2026

    @UncleBats
    Author

    The recursive error reporting on master came from #26618 ("Fix Test-Json false positive errors when using oneOf or anyOf in schema", merged Dec 2025). It was never backported to 7.6.x.

    That didn't matter in v7.6.6. There, TestJsonCommand evaluates with OutputFormat.List, which returns every error flat under the root, so checking the root and its direct Details finds them all. The shipped v7.6.7 tag evaluates with OutputFormat.Hierarchical, but ProcessRecord still calls HandleValidationErrors only on the root and its direct Details. Errors nested deeper, such as /list/1 or allOf → then → required, are never reported. (The release/v7.6.7 branch on GitHub still shows OutputFormat.List. Only the v7.6.7 tag has the switch.)

    Could the maintainers consider backporting #26618 to 7.6.x, together with the #28205 servicing change? A regression test that asserts an error is written for an array-item violation and for a nested if/then inside allOf would help keep this from coming back.

  3. SteveL-MSFT commented on Oct 21, 2026

    @SteveL-MSFT
    Member

    PowerShell team is aware of this regression and will be fixed in the next servicing release of 7.6

  4. 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

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions