Windows OS Hub
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux

 Windows OS Hub / PowerShell / Read, Modify, and Parse JSON File (Object) with PowerShell

May 8, 2024

Read, Modify, and Parse JSON File (Object) with PowerShell

JSON is a popular text-based format for representing and transmitting structured data based on JavaScript object syntax. There are two cmdlets in PowerShell that allow you to work with the JSON data format: ConvertFrom-Json and ConvertTo-Json. Let’s look at how you can use PowerShell to create, read, or modify JSON objects and save them to files.

Data in JSON format is represented as key:value pairs (property nesting is allowed). Suppose you want to write JSON data to a file. Create a JSON structured data object:

$obj = @{
    Name = "Henry"
    Roles = @{
          AD = "Admin"
          SQL = "Report"
      }
      "Company" = "woshub"
  }

Now convert the object to JSON format and save it to a file with a .json extension:

$json = $obj | ConvertTo-Json
$json | Set-Content -Path C:\PS\userroles.json

You can now read the JSON file:

$json = Get-Content -Path C:\PS\userroles.json -Raw | ConvertFrom-Json

List all JSON object properties:

$json|fl

Or you can get the value of a particular property in a JSON object:

$json.roles.sql

Use the Add-Member command to add a new property to a JSON object:

$json| Add-Member -MemberType NoteProperty -Name "Email" -Value "henry@woshub.com"

modify JSON object, add a property with PowerShell

Use the following commands to change a single value in a JSON object and save it to a file:

$json.roles.sql='Admin'
$json|ConvertTo-Json| Set-Content -Path C:\PS\userroles.json

Remove JSON object property:

$json.PSObject.Properties.Remove("Email")

By using the Invoke-WebRequest PowerShell cmdlet, you can access the JSON HTTP API to get data from external web services (sites). For example, to list A records returned by Google’s DNS service in JSON format:

$site="woshub.com"
$rawresp=Invoke-WebRequest "https://dns.google/resolve?name=$site&type=A"
$rawjson = ConvertFrom-Json -InputObject $rawresp.Content
$rawjson.answer.data

PowerShell: read JSON data from webservice

0 comment
1
Facebook Twitter Google + Pinterest
PowerShell
previous post
Configure DNS Scavenging to Clean Up Stale DNS Records in AD
next post
Create a Multi-OS Bootable USB Flash Drive with Ventoy

Related Reading

How to Install RSAT (Remote Server Administration Tools)...

November 25, 2026

Fix: Remote Desktop Licensing Mode is not Configured

August 24, 2023

Managing Windows Firewall Rules with PowerShell

March 11, 2024

Extend an Expired User Password in Active Directory

December 23, 2024

How to Allow Non-Admin User to Start/Stop Service...

November 25, 2026

How to Assign (Passthrough) a Physical GPU to...

June 11, 2024

Installing Language Pack in Windows 10/11 with PowerShell

February 19, 2026

How to Create UEFI Bootable USB Drive to...

November 25, 2026

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Managing PowerShell Modules in Windows: Install, Update & Remove

    November 24, 2026
  • Windows Installer Folder Too Large? How to Clean Up Safely

    November 12, 2026
  • Shrink WSL2 and Docker Desktop VHDX Files in Windows

    November 11, 2026
  • We Can’t Sign In to Your Account: Fix Temporary User Profile in Windows

    October 20, 2026
  • Backup/Sync to Cloud Storage with Rclone on Windows

    October 9, 2026
  • Fix Missing “Yes” Button in User Account Control Prompt on Windows

    October 7, 2026
  • Block Specific Keyboard Shortcuts with Keyboard Filter on Windows

    October 3, 2026
  • How to Set Task Priority in Windows Task Scheduler

    September 22, 2026
  • AutoStart Program at RDP Logon in Windows RDS

    September 8, 2026
  • How to Convert Windows Machine into a Proxmox VM

    August 30, 2026

Follow us

  • Facebook
  • Twitter
  • Youtube
  • Telegram
Popular Posts
  • How to Hide (Block) a Specific Windows Update
  • Fix: Slow Startup of PowerShell Console and Scripts
  • Automate Software and Settings Deployment with WinGet Configure (DSC)
  • Run Elevated Commands with Sudo on Windows 11
  • Backup/Sync to Cloud Storage with Rclone on Windows
  • Pin and Unpin Apps to Taskbar in Windows 11 via PowerShell
  • How to Pause (Delay) Update Installation on Windows 11 and 10
Footer Logo

@2014 - 2026 - Windows OS Hub. All about operating systems for sysadmins


Back To Top