'{
// A Json comment
"string": "test"
}' | Test-Json
In previous versions of PS this worked as expected.
PS> '{
// A Json comment
"string": "test"
}' | Test-Json
True
PS> '{
// A Json comment
"string": "test"
}' | Test-Json
Test-Json: Cannot parse the JSON
Exception :
Type : System.Exception
Message : Cannot parse the JSON.
InnerException :
Type : System.Text.Json.JsonReaderException
LineNumber : 1
BytePositionInLine : 4
Message : '/' is invalid after a value. Expected either ',', '}', or ']'. LineNumber: 1 | BytePositionInLine: 4.
TargetSite :
Name : ThrowJsonReaderException
DeclaringType : System.Text.Json.ThrowHelper, System.Text.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
MemberType : Method
Module : System.Text.Json.dll
Source : System.Text.Json
HResult : -2146233088
StackTrace :
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Utf8JsonReader.ConsumeNextToken(Byte marker)
at System.Text.Json.Utf8JsonReader.ConsumeNextTokenOrRollback(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.Utf8JsonReader.Read()
at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, JsonReaderOptions readerOptions, MetadataDb& database, StackRowStack& stack)
at System.Text.Json.JsonDocument.ParseUnrented(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, JsonTokenType tokenType)
at System.Text.Json.JsonDocument.ParseValue(ReadOnlyMemory`1 json, JsonDocumentOptions options)
at System.Text.Json.Nodes.JsonNode.Parse(String json, Nullable`1 nodeOptions, JsonDocumentOptions documentOptions)
at Microsoft.PowerShell.Commands.TestJsonCommand.ProcessRecord()
HResult : -2146233088
TargetObject : {
// A Json comment
"string": "test"
}
CategoryInfo : InvalidData: ({
// A Json com… "string": "test"
}:String) [Test-Json], Exception
FullyQualifiedErrorId : InvalidJson,Microsoft.PowerShell.Commands.TestJsonCommand
InvocationInfo :
MyCommand : Test-Json
ScriptLineNumber : 4
OffsetInLine : 6
HistoryId : 4
Line : }' | Test-Json
Statement : Test-Json
PositionMessage : At line:4 char:6
+ }' | Test-Json
+ ~~~~~~~~~
InvocationName : Test-Json
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
Name Value
---- -----
PSVersion 7.4.0
PSEdition Core
GitCommitId 7.4.0
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Prerequisites
Steps to reproduce
Include a comment in json, one example can be seen here:
In previous versions of PS this worked as expected.
Expected behavior
Actual behavior
Error details
Environment data
Visuals