---
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/publisher/3f95d9c85b2b81d9a96fd378dc47c60a/121705eb357e56699bca0c73e19055d636ddcfdd7418053591d9dbf69af050e2.jpg)

### [Audit Every SMB Share Permission with Get-SmbShareAccess](/audit-smb-share-permissions-powershell/)

Audit SMB share permissions with Get-SmbShareAccess, flag Everyone and Full Control grants, and check the NTFS ACL before you revoke anything.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b813190efe4fbf5ba49f1/01cf2782293526c501009180bd8555b6e73ab2cef8c62a48d76f7970916c3080.jpg)

### [Migrate DHCP Without Losing Leases with Export-DhcpServer](/migrate-dhcp-server-export-dhcpserver/)

Move a DHCP server with Export-DhcpServer and Import-DhcpServer, keeping leases intact, then authorize the new server in Active Directory.

![](https://adamtheautomator.com/wp-content/uploads/publisher/3f95d9c85b2b817aab5dca59f1ca0e14/38378bffb6e067df12a1bd90a3921833213a6e328f7d3baabd1fae698d38ddfd.jpg)

### [Fix Kerberos Clock Skew Logon Failures Using w32tm](/fix-kerberos-clock-skew-w32tm/)

Fix Kerberos clock skew logon failures by checking w32tm sources, pointing the PDC emulator at NTP, and resyncing drifted clients.

## 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/)
