You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConvertFrom-Json and ConvertTo-Json eat the one object array #2448
With the repro as is, it does look like it is by design - we enumerate objects written to the pipeline, so piping loses the fact that the object was an array. This is similar to the difference between:
The fact that it still won't work in pipeline is annoying. I have a restriction that I have to use pipeline, so I end up doing:
.\Some-Script.ps1 -OutVariable List | Out-Null; ConvertTo-Json -InputObject @($List)
And that works. I'm restricted because in this context, the script reference must be first and all other arguments are appended afterwards. I almost want a -AsArray switch or something to ConvertTo-Json.
Activity
SteveL-MSFT commentedon Oct 12, 2016
Francisco Gamino (@Francisco-Gamino) I think you had brought this up before and this was "by design"?
lzybkr commentedon Oct 26, 2016
With the repro as is, it does look like it is by design - we enumerate objects written to the pipeline, so piping loses the fact that the object was an array. This is similar to the difference between:
I was going to suggest using:
But this doesn't work either, and I would consider this a bug.
kamranayub commentedon May 19, 2017
Just ran into this the other day, the workaround I'm using is
The fact that it still won't work in pipeline is annoying. I have a restriction that I have to use pipeline, so I end up doing:
And that works. I'm restricted because in this context, the script reference must be first and all other arguments are appended afterwards. I almost want a
-AsArrayswitch or something to ConvertTo-Json.Francisco-Gamino commentedon May 19, 2017
The pipleline issue is by design; however, this is not documented, so I've create an doc issue for this: MicrosoftDocs/PowerShell-Docs#1219
For the ConvertTo-Json -InputObject $array, I cannot get it to repro. Here is what I am running:
Since the pipleline issue is by design, I am closing this. Please reopen is ConvertTo-Json -InputObject $array does not work.
gramae commentedon Jan 7, 2018
In my case this approach adds "value": at the beggining and "Count": 1 at the end:
{
"value": [
{
"name": "Animals",
"age": "1",
"children": [
{
"name": "mimi",
"age": "1",
"lovely": true,
"height": 20
},
{
"name": "dog",
"age": "2",
"lovely": false,
"height": 100
}
]
}
],
"Count": 1
}
utripathi commentedon Mar 7, 2018
Does this support complex json files .
Referring to the Azure ARM templates which are in the json format .
Does it support that too ?