Powershell stores json string psobject type 1. Define empty Hashtable 2. Iterate each property of psobject 3. Add value of psobject into Hashtable with name property as key/ Here is the script for convert JSON string to Hashtable. ```sh function ConvertJson-ToHashTable(){ [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipeline=$true )] [psobject] $inputObj) $hash = @{} $inputObj.psobject.properties | foreach{$hash[$_.Name]= [string[]]$_.Value} return $hash } ```
Azure Cloud Solution Architect, Full-Stack Development in .Net Eco system, Senior Manager at Capgemini
Monday, April 3, 2023
Convert Json string to hashtable
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment