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 should have option to produce hashtables instead of objects #3159
Json is very convenient to glue tools together.
For example, both python and powershell have ability to serialize and de-serialize anything into json without a schema.
Unfortunately, after de-serialization from json in PowerShell, you get immutable objects.
If you just get mutable hashtables, life would be much better: i.e. you can create some object in python, toss it to powershell, enhance with some info and inspect the complete result.
Although honestly, my biggest problem with json and PowerShell is that it can't ever produce the same json it received, I'm pretty sure this would make that worse unless ConvertTo-Json is fixed first ;-)
Sorry for long reply time, dropped out of my attention.
Could you clarify your original point with an example, though?
Sure, in your example $a is PsCustomObject, and not a hashtable.
The reason why it's important is because it's very common to enumerate thru the key-value pairs and apply some transformation, or try to find some value. With PSObject instead of hashtable it ever requires some step like https://stackoverflow.com/a/34383413/1355726 or doing some Get-Memeber with NoteProperty, which is pretty obscure way to do it.
Activity
Jaykul commentedon Feb 16, 2017
In theory, this makes a lot of sense to me.
Although honestly, my biggest problem with json and PowerShell is that it can't ever produce the same json it received, I'm pretty sure this would make that worse unless
ConvertTo-Jsonis fixed first ;-)vors commentedon Feb 16, 2017
Joel Bennett (@Jaykul) can you provide a specific example?
joeyaiello commentedon Feb 16, 2017
sergei (@vors): #2448 and #3153 are both examples.
Could you clarify your original point with an example, though? This seems to work fine to me:
Jaykul commentedon Feb 18, 2017
Joey Aiello (@joeyaiello): Exactly. It seems like I run into one or the other of those every time.
As far as mutability, you missed it ;-)
vors commentedon Feb 20, 2018
Sorry for long reply time, dropped out of my attention.
Sure, in your example
$ais PsCustomObject, and not a hashtable.The reason why it's important is because it's very common to enumerate thru the key-value pairs and apply some transformation, or try to find some value. With PSObject instead of hashtable it ever requires some step like https://stackoverflow.com/a/34383413/1355726 or doing some
Get-Memeberwith NoteProperty, which is pretty obscure way to do it.markekraus commentedon Feb 20, 2018
Hmm isn't this issue resolved?
ConvertFrom-Json -AsHashtablewas added in #5043.vors commentedon Feb 21, 2018
Ah indeed, awesome!