CmdID / PowerShell / Cmdlets / ConvertFrom
ConvertFrom-Json
Converts a JSON-formatted string to a custom object. PowerShell reference
From the PowerShell reference 1 parameter
What it does
Converts a JSON-formatted string to a custom object. The ConvertFrom-Json cmdlet converts a JavaScript Object Notation (JSON) formatted string to a custom PSObject or Hashtable object that has a property for each field in the JSON string. JSON is commonly used by web sites to provide a textual representation of objects. The cmdlet adds the properties to the new object as it processes each line of the JSON string. The JSON standard allows duplicate key names, which are prohibited in PSObject and Hashtable types. For example, if the JSON string contains duplicate keys, only the last key is used by this cmdlet. See other examples below. To generate a JSON string from any object, use the ConvertTo-Json cmdlet. This cmdlet was introduced in PowerShell 3.0. NOTE: In Windows PowerShell 5.1, ConvertFrom-Json returns an error when it encounters a JSON comment. In PowerShell 6 and higher, the cmdlet supports JSON with comments. JSON comments aren't captured in the objects output by the cmdlet. For more information, see the _JSON comments_ section of the about_Comments article.
ConvertFrom-Json [-InputObject] <String> [<CommonParameters>]
Convert a DateTime object to a JSON object
Get-Date | Select-Object -Property * | ConvertTo-Json | ConvertFrom-JsonIdentifyGet JSON strings from a web service and convert them to PowerShell objects
# Ensures that Invoke-WebRequest uses TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$j = Invoke-WebRequest 'https://api.github.com/repos/PowerShell/PowerShell/issues' |
ConvertFrom-JsonIdentifyTrips 1 Sigma rule: mediumUsage Of Web Request Commands And Cmdlets by James Pemberton / @4A616D6573, Endgame, JHasenbusch, oscd.community, Austin Songer @austinsonger
Convert a JSON string to a custom object
Get-Content -Raw JsonFile.json | ConvertFrom-JsonIdentifyIts page in the reference: ConvertFrom-Json.
Parameters
-InputObjectSpecifies the JSON strings to convert to JSON objects. Enter a variable that contains the string, or type a command or expression that gets the string. You can also pipe a string to ConvertFrom-Json.
The InputObject parameter is required, but its value can be an empty string. When the input object is an empty string, ConvertFrom-Json doesn't generate any output. The InputObject value can't be $null.