---
title: "How to Work with JSON in PowerShell: A Practical Guide"
description: "Learn how to effectively read, manipulate and write JSON data using PowerShell with real-world examples. Master JSON handling for sysadmin tasks."
canonical: "https://adamtheautomator.com/powershell-json-tutorial/"
---

# How to Work with JSON in PowerShell: A Practical Guide

> Learn how to effectively read, manipulate and write JSON data using PowerShell with real-world examples. Master JSON handling for sysadmin tasks.

Source: https://adamtheautomator.com/powershell-json-tutorial/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Work with JSON in PowerShell: A Practical Guide](https://adamtheautomator.com/wp-content/uploads/2024/11/image-47.png)

# How to Work with JSON in PowerShell: A Practical Guide

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)18 November 20242 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Reading JSON Files in PowerShell](#reading-json-files-in-powershell)
*   [Manipulating JSON Data](#manipulating-json-data)
*   [Saving Modified JSON Data](#saving-modified-json-data)
*   [Common Pitfalls to Avoid](#common-pitfalls-to-avoid)
*   [Conclusion](#conclusion)

As a Windows systems administrator, working with JSON (JavaScript Object Notation) data is increasingly becoming a crucial skill. Whether you’re parsing configuration files, interacting with REST APIs, or managing application data, knowing how to handle JSON efficiently in PowerShell can save you hours of work. In this hands-on tutorial, I’ll show you the practical side of working with JSON in PowerShell.

#### Prerequisites

Before diving in, make sure you have:

*   PowerShell 5.1 or higher installed (all examples use PowerShell 7)
*   Basic familiarity with PowerShell cmdlets and pipelines
*   A text editor of your choice (I’ll be using VS Code)

#### Reading JSON Files in PowerShell

Let’s start with a basic example. Say you have a JSON file called `People.json` containing information about several people:

```
[
  {
    "Name": "John Smith",
    "Age": 30,
    "City": "New York"
  },
  {
    "Name": "Jane Doe",
    "Age": 25,
    "City": "Los Angeles"
  }
]
```

To read this JSON file into PowerShell, we use a combination of `Get-Content` and `ConvertFrom-Json`:

```
$people = Get-Content -Path ~\People.json | ConvertFrom-Json
$people
```

The magic happens in the `ConvertFrom-Json` cmdlet – it transforms the raw JSON text into PowerShell objects that you can easily work with. When you run this command, PowerShell displays the data in a structured format:

![](https://adamtheautomator.com/wp-content/uploads/2024/11/2024-11-17_15-38-14.png)

#### Manipulating JSON Data

One of the best parts about converting JSON to PowerShell objects is that you can manipulate the data just like any other PowerShell object. Here’s how to modify values:

```
# Change the city of the first person
$people[0].City = 'Chicago'

# View the changed object
$people[0]
```

The real power comes when you need to filter or transform the data. For example, to find everyone over 25 years old:

```
$people | Where-Object { $_.Age -gt 25 }
```

This is MUCH simpler than trying to parse the JSON directly with regular expressions, which would look something like this monstrosity:

```
$regexPattern = '({[^}]"Age"\s:\s(?:[2-9][6-9]|[3-9][0-9]|[1-9][0-9]{2,})[^}]})'
$matches = [regex]::Matches($jsonFromFile, $regexPattern)
```

Trust me, you don’t want to go down that path unless absolutely necessary!

#### Saving Modified JSON Data

After making changes to your data, you’ll probably want to save it back to a file. Here’s how to convert PowerShell objects back to JSON:

```
$people | ConvertTo-Json | Set-Content -Path ~\UpdatedPeople.json
```

This pipeline:

1.  Takes your PowerShell objects ($people)
2.  Converts them back to JSON format (ConvertTo-Json)
3.  Saves the JSON to a new file (Set-Content)

To verify the changes, you can read the new file:

```
Get-Content -Path ~\UpdatedPeople.json
```

#### Common Pitfalls to Avoid

1.  **Encoding Issues**: If you see strange characters in your JSON, make sure you’re using the correct encoding when reading/writing files
2.  **Depth Limitations**: By default, \`ConvertTo-Json\` only converts 2 levels deep. Use the \`-Depth\` parameter for deeper objects
3.  **Special Characters**: Watch out for special characters in JSON strings – they need proper escaping

#### Conclusion

Working with JSON in PowerShell doesn’t have to be complicated. By leveraging built-in cmdlets like `ConvertFrom-Json` and `ConvertTo-Json`, you can easily read, manipulate, and write JSON data without wrestling with complex regular expressions or string manipulation.

The next time you need to work with JSON data in your PowerShell scripts, remember this simple workflow:

1.  Read the JSON file with Get-Content
2.  Convert it to PowerShell objects with ConvertFrom-Json
3.  Manipulate the data using standard PowerShell commands
4.  Save the changes using ConvertTo-Json and Set-Content

Have you found other useful techniques for working with JSON in PowerShell? Share your experiences in the comments below!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-json-tutorial%2F&text=How%20to%20Work%20with%20JSON%20in%20PowerShell%3A%20A%20Practical%20Guide)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-json-tutorial%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-json-tutorial%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
