JSON to PowerShell Hashtable Converter — Free Online Tool
Convert JSON to PowerShell hashtable or PSCustomObject syntax using AI. Handles nested objects, arrays, nulls, and booleans with correct PowerShell syntax. Free, no sign-up.
JSON to PowerShell Hashtable Converter — Free Online Tool
About JSON to PowerShell Hashtable Converter — Free Online Tool
JSON to PowerShell converts a JSON object into PowerShell hashtable or PSCustomObject syntax, making it immediately usable in scripts, DSC configurations, and automation workflows. System administrators and developers use it to translate API responses or configuration payloads into native PowerShell data structures without manually rewriting bracket syntax.
JSON to PowerShell Type Mapping
| JSON Type | PowerShell Type | Example Output |
|---|---|---|
| string | String | @{name = 'Alice'} |
| integer | Int32 / Int64 | @{port = 8080} |
| float | Double | @{ratio = 3.14} |
| boolean true | Boolean ($true) | @{enabled = $true} |
| boolean false | Boolean ($false) | @{enabled = $false} |
| null | $null | @{value = $null} |
| object | Nested @{} | @{db = @{host = 'localhost'}} |
| array of strings | String[] | @{tags = @('a','b')} |
| array of objects | Array of @{} | @{items = @(@{id=1},@{id=2})} |
PowerShell JSON Cmdlets Reference
| Cmdlet | Purpose | Key Note |
|---|---|---|
| ConvertFrom-Json | JSON string → PSCustomObject | Dot notation access: $obj.name |
| ConvertTo-Json | Object → JSON string | Always use -Depth 10+ to avoid truncation |
| Invoke-RestMethod | HTTP call → auto-parsed object | Parses JSON automatically |
| Invoke-WebRequest | HTTP call → raw response | Use .Content then ConvertFrom-Json |
| Get-Content | ConvertFrom-Json | Read JSON file | Use -Raw flag for single string |
| ConvertTo-Json | Set-Content | Write JSON file | Pipe chain for file output |
Frequently Asked Questions
How do I parse JSON in PowerShell?
Use ConvertFrom-Json: $obj = $jsonString | ConvertFrom-Json. The output is a PSCustomObject with properties matching JSON keys, accessible via dot notation ($obj.name). For JSON files: $obj = Get-Content 'file.json' -Raw | ConvertFrom-Json. The -Raw flag reads the file as a single string rather than an array of lines.
Why does ConvertTo-Json truncate my nested objects?
ConvertTo-Json has a default depth of 2, which truncates objects nested deeper than two levels. Always use -Depth 10 (or higher): $obj | ConvertTo-Json -Depth 10. This is the most common PowerShell JSON pitfall — missing -Depth causes silent data loss in the output.
What is the difference between a PowerShell hashtable and PSCustomObject?
A hashtable (@{key = 'value'}) is a dictionary accessed with brackets ($ht['key']). A PSCustomObject ([PSCustomObject]@{key = 'value'}) is a proper object with properties, supported by Format-Table and Select-Object. ConvertFrom-Json always returns PSCustomObject; both work with ConvertTo-Json but PSCustomObject serializes more reliably.
How do I convert a PowerShell hashtable to JSON?
Call ConvertTo-Json: @{name='Alice'; age=30} | ConvertTo-Json -Depth 5. For ordered keys, use [ordered]@{} instead of @{}, which outputs keys in insertion order. This is important when the JSON consumer expects a specific key ordering.
How do I call a REST API and work with JSON in PowerShell?
Use Invoke-RestMethod which automatically parses JSON responses: $result = Invoke-RestMethod -Uri 'https://api.example.com/data' -Method GET. For POST with JSON body: Invoke-RestMethod -Uri $url -Method POST -ContentType 'application/json' -Body ($body | ConvertTo-Json -Depth 10). Always convert the body to string first.
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.