Skip to content

Instantly share code, notes, and snippets.

@vexx32
Created May 15, 2020 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/7d2b99dc4c5ce6520d37bfa6e4a58f29 to your computer and use it in GitHub Desktop.
Save vexx32/7d2b99dc4c5ce6520d37bfa6e4a58f29 to your computer and use it in GitHub Desktop.
Converts a JSON object into a PSObject, replacing these_property_names with ThesePropertyNames
$Object = ConvertFrom-Json '{ "base_url": "https://foo.bar" }'
$Properties = foreach ($property in $Object.PSObject.Properties) {
$newNameFragments = @($property.Name -split '_').ForEach{
[CultureInfo]::CurrentCulture.TextInfo.ToTitleCase($_)
}
# Select-Object property rename via selector hashtable; Name is the new name, Expression is the original name
@{ Name = -join $newNameFragments; Expression = $property.Name }
}
$Object | Select-Object -Property $Properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment