Created
May 15, 2020 15:14
-
-
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
This file contains 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
$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