- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert JSON object to Hashtable format using PowerShell?
PowerShell 7 supports the -AsHashtable parameter in the ConvertFrom−JSON command to convert the JSON to hashtable directly and that is a great feature. Consider we have the below JSON file,
We can use the pipeline command ConvertFrom−JSON to convert the JSON file to the custom table format and with the −AsHashtable parameter to convert the custom object to the hashtable.
PS C:\Temp> Get-Content .\testsevent.json | ConvertFrom-Json -AsHashtable Name Value ---- ----- Events {602d9444−d2cd−49c7−8624−8643e7171297} DocumentIncarnation 0
To retrieve the data,
PS C:\Temp> $out = Get−Content .\testsevent.json | ConvertFrom−Json −AsHashtable PS C:\Temp> $out.Events
Output
PS C:\Temp> $out.Events Name Value ---- ----- Description Host server is undergoing maintenance. EventStatus Scheduled EventId 602d9444−d2cd−49c7−8624−8643e7171297
For the PowerShell framework version, −AsHashTable parameter is not supported and in that case, you need to convert it to the hashtable manually as shown below.
$out = Get−Content .\testsevent.json | ConvertFrom−Json
Code to convert JSON to Hashtable,
$hash = @{} $out.psobject.properties | foreach{$hash[$_.Name]= $_.Value} $hash
Output
- Related Articles
- How to convert the hashtable to the JSON format using PowerShell?
- How to convert command output to the Hashtable format in PowerShell?
- How to convert JSON to CSV file using PowerShell?
- How to convert Dictionary to Hashtable in PowerShell?
- How to convert JSON file to CSV file using PowerShell?
- Convert a JSON object to XML format in Java?\n
- How to convert Java object to JSON using GSON library?
- How to convert Java object to JSON using Jackson library?
- How to convert JSON text to JavaScript JSON object?
- How to convert Python date in JSON format?
- How to convert a Map to JSON object using JSON-lib API in Java?
- Convert JSON to another JSON format with recursion JavaScript
- Explain JSON format in PowerShell.
- How to format string using PowerShell?
- How to convert the JSON object to a bean using JSON-lib API in Java?

Advertisements