ConvertFrom-Json

Convert a JSON-formatted string to a custom object.

Syntax
      ConvertFrom-Json [-InputObject] String [CommonParameters]

Key
   -InputObject String
        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 does not generate any output.

        The -InputObject value cannot be $Null.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer, -PipelineVariable, -OutVariable.

Standard Aliases for ConvertFrom-Json: none, but if you want to add a short alias like cfjn, set it with set-alias

This cmdlet was introduced in Windows PowerShell 3.0.

Examples

Convert a DateTime object to a JSON object:

PS C:\> Get-Date | Select-Object -Property * | ConvertTo-Json | ConvertFrom-Json

This command uses the Select-Object cmdlet to get all of the properties of the DateTime object. It uses ConvertTo-Json to convert the DateTime object to a JSON-formatted string and ConvertFrom-Json to convert the JSON-formatted string to a JSON object. The object properties: Date, Day, Hour etc are then displayed on screen.

Get JSON strings from a web service and convert them to Windows PowerShell objects:

PS C:\> $j = Invoke-WebRequest -Uri http://search.twitter.com/search.json?q=PowerShell | ConvertFrom-Json
https://en.wikipedia.org/wiki/PowerShell#/media/File:PowerShell_Core_6.0_icon.png

“The price of anything is the amount of life you exchange for it” ~ Henry David Thoreau

Related PowerShell Cmdlets:

ConvertTo-Json - Convert an object to a JSON-formatted string.


 
Copyright © SS64.com 1999-2020
Some rights reserved