1

I was intrigued with this example:

PS /home/nicholas> 
PS /home/nicholas> $json = '[ { "hello": 1 } ]'              
PS /home/nicholas> $json | ConvertFrom-Json | ConvertTo-Json 
{
  "hello": 1
}
PS /home/nicholas> $json | ConvertTo-Json | ConvertFrom-Json 
[ { "hello": 1 } ]
PS /home/nicholas> 
PS /home/nicholas> $json | ConvertFrom-Json | ConvertTo-Json 
{
  "hello": 1
}
PS /home/nicholas> 

and am interested as to why it won't "round trip" correctly. Is it really any different? Seems a difference without distinction, perhaps.

Incidentally, what is powershell converting "from" and "to"? Help file says:

DESCRIPTION The ConvertTo-Json cmdlet converts any .NET object to a string in JavaScript Object Notation (JSON) format.

here, I suppose, String.


I'm not seeing that any information is gained or lost in the above cycle. Perhaps I'm not understanding the concern.

  • 1
    This is a known issue and has to do with how PowerShell unrolls arrays into the pipeline. Does this answer your question? [How to convert powershell array to json using ConvertTo-Json?](https://stackoverflow.com/questions/58617070/how-to-convert-powershell-array-to-json-using-convertto-json) – iRon Nov 18 '20 at 16:09
  • it's certainly useful, but I think it has more to do with https://stackoverflow.com/q/53583677/4531180 and between the two questions there's no need for this q. – Nicholas Saunders Nov 18 '20 at 20:09

0 Answers0