Skip to content

Instantly share code, notes, and snippets.

@dfinke
Last active July 15, 2024 09:25
Show Gist options
  • Save dfinke/5423910 to your computer and use it in GitHub Desktop.
Save dfinke/5423910 to your computer and use it in GitHub Desktop.
$json="
{
'name': 'john doe',
'age':10,
'pets': []
}
"
$json |
ConvertFrom-Json |
Get-Member -MemberType NoteProperty | ForEach {
[PSCustomObject]@{
Name = $_.Name
Type = (($_.Definition -split ' ')[0] -split '\.')[1]
}
} | ForEach {$property=@()} {
$property += "`tpublic {0} {1} {{get; set;}}`r`n" -f $_.Type, $_.Name
} {
@"
public class RootObject
{
$property
}
"@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment