JSON
JavaScript Object Notation (JSON) is a data format that is easily read by humans and quickly parsed by machines. It has become very popular in combination with REST and for web services, but it is also used for storing configuration data. The following examples show how to work with the two cmdlets called ConvertTo-Json
and ConvertFrom-Json
:
#Exporting Services to JSON $ServicesAsJSON = Get-Service | Select-Object -Property DisplayName, ServiceName, Status, StartType | ConvertTo-Json #Converting exported JSON object to hashtable $importedServices =$ServicesAsJSON | ConvertFrom-Json #Show $importedServices | Out-GridView #Different types (Get-Service)[0].GetType()#ServiceController $importedServices[0].GetType()#PSCustomObject $importedServices.GetType()#HashTable -- Array #Loading some JSON data into variable $someJSONdata ='{"people":[ { "firstName":"John", "lastName":"Doe" }, { "firstName":"Jane", "lastName":"Dane" } ]}' #Converting exported JSON object to hashtable $ConvertedDataFromJSON...