diff --git a/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj b/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj
index ea5e0bd22a..2972c210a6 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj
+++ b/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj
@@ -35,7 +35,7 @@
-
+
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs
index 4a6e11a963..edb83a0841 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/TestJsonCommand.cs
@@ -239,32 +239,20 @@ namespace Microsoft.PowerShell.Commands
if (_jschema != null)
{
- var validationResults = _jschema.Validate(parsedJson, new ValidationOptions { OutputFormat = OutputFormat.Basic });
- result = validationResults.IsValid;
- if (!result)
+ EvaluationResults evaluationResults = _jschema.Evaluate(parsedJson, new EvaluationOptions { OutputFormat = OutputFormat.List });
+ result = evaluationResults.IsValid;
+ if (!result)
+ {
+ HandleValidationErrors(evaluationResults);
+
+ if (evaluationResults.HasDetails)
{
- if (validationResults.Message != null)
+ foreach (var nestedResult in evaluationResults.Details)
{
- Exception exception = new(string.Format(TestJsonCmdletStrings.InvalidJsonAgainstSchemaDetailed, validationResults.Message, validationResults.InstanceLocation));
- ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchemaDetailed", ErrorCategory.InvalidData, null);
- WriteError(errorRecord);
- }
-
- if (validationResults.HasNestedResults)
- {
- foreach (var nestedResult in validationResults.NestedResults)
- {
- if (nestedResult.Message == null)
- {
- continue;
- }
-
- Exception exception = new(string.Format(TestJsonCmdletStrings.InvalidJsonAgainstSchemaDetailed, nestedResult.Message, nestedResult.InstanceLocation));
- ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchemaDetailed", ErrorCategory.InvalidData, null);
- WriteError(errorRecord);
- }
+ HandleValidationErrors(nestedResult);
}
}
+ }
}
}
catch (JsonSchemaReferenceResolutionException jsonExc)
@@ -284,5 +272,20 @@ namespace Microsoft.PowerShell.Commands
WriteObject(result);
}
+
+ private void HandleValidationErrors(EvaluationResults evaluationResult)
+ {
+ if (!evaluationResult.HasErrors)
+ {
+ return;
+ }
+
+ foreach (var error in evaluationResult.Errors!)
+ {
+ Exception exception = new(string.Format(TestJsonCmdletStrings.InvalidJsonAgainstSchemaDetailed, error.Value, evaluationResult.InstanceLocation));
+ ErrorRecord errorRecord = new(exception, "InvalidJsonAgainstSchemaDetailed", ErrorCategory.InvalidData, null);
+ WriteError(errorRecord);
+ }
+ }
}
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx b/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx
index eed85d28b3..cc607eda41 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx
+++ b/src/Microsoft.PowerShell.Commands.Utility/resources/TestJsonCmdletStrings.resx
@@ -124,7 +124,7 @@
Cannot parse the JSON.
- The JSON is not valid with the schema: {0} at {1}
+ The JSON is not valid with the schema: {0} at '{1}'
Can not open JSON schema file: {0}
diff --git a/tools/packaging/boms/windows.json b/tools/packaging/boms/windows.json
index 747fa838b5..75b6ddf326 100644
--- a/tools/packaging/boms/windows.json
+++ b/tools/packaging/boms/windows.json
@@ -287,6 +287,10 @@
"Pattern": "es/WindowsFormsIntegration.resources.dll",
"FileType": "NonProduct"
},
+ {
+ "Pattern": "es\\JsonSchema.Net.resources.dll",
+ "FileType": "NonProduct"
+ },
{
"Pattern": "fr/Microsoft.CodeAnalysis.CSharp.resources.dll",
"FileType": "NonProduct"