In previous posts I showed Convert-FromJSON as both a PowerShell script and C# implementation.
They are now hosted as open source in CodePlex. Also available is the Cmdlet source wrapping the C#, showing another integration path for PowerShell.
Douglas Crockford, author of JavaScript Object Notation, was kind enough to add a link to json.org. Thank you sir.
{ 4 comments… read them below or add one }
got to love opensource – thanks Doug!!!!
Nice work, Douglas. In fact, this inspired me to add PowerShell scripting support to Jayrock (http://jayrock.berlios.de/), which is also an open source library that adds JSON support to .NET Framework in various forms. Here’s first using Jayrock from PowerShell to import JSON (nothing special here)…
PS C:\> [Reflection.Assembly]::LoadFile(’C:\Jayrock\bin\Jayrock.Json.dll’)
GAC Version Location
— ——- ——–
False v1.1.4322 C:\Jayrock\bin\Jayrock.Json.dll
PS C:\> [Jayrock.Json.Conversion.JsonConvert]::Import(’[{"title":"PowerShell"},{"title":"Test"}]‘)
Name Value
—- —–
title PowerShell
title Test
One of the things Jayrock allows you to do is to expose web services using JSON-RPC. The bit of twist I added now is to dynamically generate a PowerShell script from the server so you can call server-side methods and automate the service. Here’s how to download the PowerShell proxy (here pointing to a demo service running on my site):
PS C:\> $wc = New-Object Net.WebClient
PS C:\> $wc.DownloadString(’http://www.raboof.com/projects/jayrock/demo.ashx?ps1proxy’) | Invoke-Expression
Hey, this does not even require you to change the script execution policy.
With this, you now get a function called DemoService (based on your service) that you can call to create an instance of the proxy:
PS C:\> $s = DemoService
Next, just start calling the methods of this object…
PS C:\> $s.now()
2007-06-22T09:21:03.8324368-06:00
PS C:\> [int] $s.sum(123, 456)
579
If you pipe $s to Get-Member, you’ll see how the proxy is setup.
Anyway, would appreciate your feedback, epsecially if you manage to find some time take a peek at the proxy code and offer some suggestions.
Excellent. Yes I played a bit with Jayrock.
I used it before I decided to write this parser.
Good stuff. I will take a look and let you know.
Looks like this doesn’t handle escaped characters like \r\n or an escaped quotation like \”