Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Breaking Change: JSONC no longer works after 7.4.0 #20782

Copy link
Copy link
@kyle-ntx

Description

@kyle-ntx
Issue body actions

Prerequisites

Steps to reproduce

Include a comment in json, one example can be seen here:

'{
    // A Json comment
    "string": "test"
}' | Test-Json

In previous versions of PS this worked as expected.

Expected behavior

PS> '{
    // A Json comment
    "string": "test"
}' | Test-Json
True

Actual behavior

PS> '{
    // A Json comment
    "string": "test"
}' | Test-Json

Test-Json: Cannot parse the JSON

Error details

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 :

Environment data

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

Visuals

image
image

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core modulecmdlets in the Microsoft.PowerShell.Core moduleWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.