Wow, it has been 4 years since I put Convert between PowerShell and JSON up on CodePlex.
This week Microsoft released the Windows Developer Preview and PowerShell V3 was also delivered. Two of the new commands included, ConvertTo-JSON and ConvertFrom-JSON.
I had fun building these scripts. From it I learned that PowerShell didn’t support Tail Call Optimization and ended up using the Trampoline Method. Those were my early days working with PowerShell. We’ve both survived and come along way and are much stronger for it.
I’m looking forward to V3 being fully baked and released with Windows 8 and Windows 8 Server.
Here is my original post Implementing a JSON parser.
These are the examples I put on the CodePlex page and the work verbatim with V3.
PS C:\> '[{"title":"PowerShell"},{"title":"Test"}]' | ConvertFrom-JSON
title
-----
PowerShell
Test
(New-Object PSObject |
Add-Member -PassThru NoteProperty Name 'John Doe' |
Add-Member -PassThru NoteProperty Age 10 |
Add-Member -PassThru NoteProperty Amount 10.1 |
Add-Member -PassThru NoteProperty MixedItems (1,2,3,"a") |
Add-Member -PassThru NoteProperty NumericItems (1,2,3) |
Add-Member -PassThru NoteProperty StringItems ("a","b","c")
) | ConvertTo-JSON
{
"Name": "John Doe",
"Age": 10,
"Amount": 10.1,
"MixedItems": [
1,
2,
3,
"a"
],
"NumericItems": [
1,
2,
3
],
"StringItems": [
"a",
"b",
"c"
]
}





{ 4 trackbacks }
{ 0 comments… add one now }