Created
September 20, 2018 17:57
-
-
Save mattmcnabb/2037f64f85e9f1b42fd2749e912f8407 to your computer and use it in GitHub Desktop.
Wrap Json with C# class in PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add-type -Path .\newtonsoft.json.dll | |
$CSharp = @" | |
namespace json | |
{ | |
public class demo | |
{ | |
public string prop1 {get; set;} | |
public int prop2 {get; set;} | |
public string[] prop3 {get; set;} | |
} | |
} | |
"@ | |
Add-Type -TypeDefinition $Csharp | |
$json = @" | |
{ | |
'Prop1': 'Value1', | |
'Prop2': 8, | |
'Prop3': [ | |
'a string', | |
'another one' | |
], | |
'Prop4': 'nuffin' | |
} | |
"@ | |
$output = [Newtonsoft.Json.JsonConvert]::DeserializeObject($json, [json.demo]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment