Skip to content

Instantly share code, notes, and snippets.

@Iristyle
Created April 18, 2014 17:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Iristyle/11056390 to your computer and use it in GitHub Desktop.
Save Iristyle/11056390 to your computer and use it in GitHub Desktop.
PS2 JSON Polyfill
function ConvertFrom-JsonString
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string]
$Json
)
Add-Type -AssemblyName System.Web.Extensions
$jsSerializer = New-Object Web.Script.Serialization.JavaScriptSerializer
return $jsSerializer.DeserializeObject($json)
}
function ConvertTo-JsonString
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[AllowNull()]
[PSObject]
$InputObject
)
Add-Type -AssemblyName System.Web.Extensions
$jsSerializer = New-Object Web.Script.Serialization.JavaScriptSerializer
return $jsSerializer.Serialize($InputObject)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment