In this post, the “ConvertFrom-Json” cmdlet will be explained in detail.
What is ConvertFrom-Json (Microsoft.PowerShell.Utility)?
JSON is most commonly utilized by websites to give a visual representation of objects or a hash table. Let’s overview some of the examples explaining the stated cmdlet.
Example 1: Convert a DateTime Object to a JSON Object
Execute the below-given command to convert “DateTime” to a JSON object:
Following the above-stated code:
- First, specify the “Get-Date” cmdlet along with the “|” pipeline.
- Then, write the “Select-Object” to select a property along with the “-Property” parameter and the “*” wildcard.
- After that, add another “|” pipeline alongside the “ConvertTo-Json” cmdlet and the pipeline “|”.
- Lastly, mention the “ConvertFrom-Json” cmdlet:
Example 2: Convert a JSON String to a Hash Table
To convert a JSON string to a hash table, run the below code:
In the above-stated code:
- First, write a hash table having the specified values.
- Then, use the “|” pipeline and add the “ConvertFrom-Json” cmdlet.
- Lastly, mention the “-AsHashtable” parameter at the end:
That was all about the “ConvertFrom-Json” cmdlet in PowerShell.