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)...

March 24, 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...

March 15, 2024

Installing Language Pack in Windows 10/11 with PowerShell

February 19, 2026

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

June 11, 2024

How to Create UEFI Bootable USB Drive to...

March 13, 2024

Leave a Comment Cancel Reply

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

Recent Posts

  • Updating UEFI Secure Boot Certificates on Windows Devices Explained

    April 20, 2026
  • Security Warnings When Opening RDP Files in Windows 11

    April 17, 2026
  • Find Computers with Pending Reboot Status Using PowerShell

    April 15, 2026
  • Mounting NFS Shares in Windows Using the Built-in Client

    March 26, 2026
  • Monitor Windows Log Files in Real Time with PowerShell

    March 17, 2026
  • Pin and Unpin Apps to Taskbar in Windows 11 via PowerShell

    March 10, 2026
  • Load and Initialize Network Drivers in Windows PE or Recovery Environment

    February 25, 2026
  • How to Set a Custom Drive Icon in Windows

    February 17, 2026
  • Managing Per-User Services in Windows

    February 11, 2026
  • Change Default OU for New Computers and Users in AD

    February 2, 2026

Follow us

  • Facebook
  • Twitter
  • Youtube
  • Telegram
Popular Posts
  • How to Delete Old User Profiles in Windows
  • Fix: Remote Desktop Licensing Mode is not Configured
  • How to Install RSAT (Remote Server Administration Tools) on Windows
  • Configuring User Profile Disks (UPD) on Windows Server RDS
  • How to Create UEFI Bootable USB Drive to Install Windows
  • Wi-Fi (Internet) Disconnects After Sleep or Hibernation on Windows 10/11
  • How to Allow Non-Admin User to Start/Stop Service in Windows
Footer Logo

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


Back To Top