Project Description
PowerShell objects from JSON data. A script, dll and snapin for deserializing JSON data into PowerShell objects.
This project contains three approaches to
deserializing JSON formatted data into
PowerShell Objects.
- A PowerShell script
- The PowerShell script converted to C# and compiled as a managed DLL
- The managed DLL implemented as a PowerShell SnapIn
The Script
Place the script in a directory which is in your path
Managed DLL
The managed code stand alone version needs to load the dll with
[reflection.assembly]::LoadFrom("") for each session
[void] [reflection.assembly]::loadfrom("$pwd\bin\debug\PowerShellJSONParser.dll")
The SnapIn
The snapin needs to be registered. This is only required once.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe $pwd\bin\Debug\PowerShellJSONParser.dll
But the snapin must be added each session.
Add-PSSnapin ConvertFromJSONSnapIn
This can be simplfied by using the
Export-Console Cmdlet.
Export-Console ConvertFromJSON
Performance
- The PowerShell script is the slowest but easiest to modify.
- The managed code requires re-compiliation.
Examples
The examples are the same for each implementation.
PS C:\> '[{"title":"PowerShell"},{"title":"Test"}]' | Convert-FromJSON | Invoke-Expression
title
-----
PowerShell
Test