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

ConvertFrom-Json and ConvertTo-Json eat the one object array #2448

Copy link
Copy link
@SummerSun

Description

@SummerSun
Issue body actions

OS info

Edition: Windows 10 Enterprise
Version: 1607
OS Build: 14393.187
Installed RAM: 16.0 GB
System Type: 64-bit operating system, x64-based processor

Steps to reproduce

  1. Create a .json file. Write in an array with only one valid json object:
[{
    "name": "Animals",
    "age": "1",
    "children": [{
        "name": "mimi",
        "age": "1",
        "lovely": true,
        "height": 20
    },
    {
        "name": "dog",
        "age": "2",
        "lovely": false,
        "height": 100
    }]
}]
  1. Convert this json file content to psobject and then convert it back to write it to another file
$o=(Get-Content -Raw D:\Test_Convert.json | ConvertFrom-Json)
Set-Content 'D:\result.json' ($o | ConvertTo-Json)
  1. View the result.json:
{
    "name":  "Animals",
    "age":  "1",
    "children":  [
                     {
                         "name":  "mimi",
                         "age":  "1",
                         "lovely":  true,
                         "height":  20
                     },
                     {
                         "name":  "dog",
                         "age":  "2",
                         "lovely":  false,
                         "height":  100
                     }
                 ]
}

Expected behavior

Get the right PSObject and write the same content back.

Actual behavior

The array turns into its only child.

Environment data

Included in the repro steps.

Powershell Version

PS C:\Users\qisun\Downloads\LatestPowerShell> $PSVersionTable.PSVersion

Major Minor Patch Label
----- ----- ----- -----
    6     0     0 alpha

Have to mention that the issue does not repro when there are multiple children in that array.

Reactions are currently unavailable

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

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.