Skip to content

ConvertFrom-Json returns array with extra null element, if comments are outside the root element. #21203

Description

@mubed

Prerequisites

Steps to reproduce

Having a json file containing this:

// Comment on top level
{
    "key": "value"
}

should become a PSObject or Hashtable, when imported using Get-Content and then piped through ConvertFrom-Json, but the result is an array with a null as first element and the PSObject/Hashtable as the second element!

Expected behavior

Comment lines have to be ignored, not be included as null elements.

Actual behavior

Comments on top level are interpreted as null elements like a "{}".

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
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

No response

Activity

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

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions