PowerShell V3 in Preview

Windows 8 was released on 9/12/2011 and with it came PowerShell V3.
Included in PowerShell V3 are two new functions ConvertFrom-Json, ConvertTo-Json.
The code in this project can be used in previous versions of PowerShell.

Please note, this is not as robust as what the Microsoft PowerShell team delivered and I will not be making any additions to it.

I encourage you to get PowerShell V3 and try out these commands. There are many sites which support JSON. PowerShell V3 will interact with them nicely.

In fact. The examples below work great in V3.

Thanks

Doug

Examples

ConvertFrom-JSON

PS C:\> '[{"title":"PowerShell"},{"title":"Test"}]' | ConvertFrom-JSON

title
-----
PowerShell
Test

ConvertTo-JSON

(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

Generated JSON

{
  "Age": 10,
  "Amount": 10.1,
  "MixedItems": [1,2,3,"a"],
  "Name": "John Doe",
  "NumericItems": [1,2,3],
  "StringItems": ["a","b","c"] 
}

Last edited Sep 16, 2011 at 1:27 AM by dfinke, version 27