0
0
PowerShellscripting~30 mins

JSON operations (ConvertFrom-Json, ConvertTo-Json) in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
JSON operations (ConvertFrom-Json, ConvertTo-Json)
📖 Scenario: You work in a small company that stores employee information in JSON format. You want to read this data, update it, and then save it back as JSON.
🎯 Goal: Learn how to convert JSON text into PowerShell objects using ConvertFrom-Json, modify the data, and then convert it back to JSON text using ConvertTo-Json.
📋 What You'll Learn
Create a JSON string variable with employee data
Convert the JSON string to a PowerShell object
Add a new employee to the object
Convert the updated object back to JSON and display it
💡 Why This Matters
🌍 Real World
Many systems use JSON to store and exchange data. PowerShell scripts often need to read, update, and write JSON data for automation tasks.
💼 Career
Understanding JSON operations in PowerShell is useful for IT administrators, DevOps engineers, and automation specialists who manage configurations and data in JSON format.
Progress0 / 4 steps
1
Create a JSON string with employee data
Create a variable called jsonData and assign it this exact JSON string: '{"employees":[{"name":"Alice","age":30},{"name":"Bob","age":25}]}'
PowerShell
Need a hint?

Use single quotes around the JSON string to avoid escaping double quotes inside.

2
Convert JSON string to PowerShell object
Use ConvertFrom-Json to convert jsonData into a variable called employeeObj.
PowerShell
Need a hint?

Use $employeeObj = ConvertFrom-Json $jsonData to convert the JSON string.

3
Add a new employee to the object
Add a new employee with name "Charlie" and age 28 to the employees array inside employeeObj.
PowerShell
Need a hint?

Use $employeeObj.employees += @{name='Charlie'; age=28} to add the new employee.

4
Convert the updated object back to JSON and display it
Use ConvertTo-Json to convert employeeObj back to JSON and print it with Write-Output.
PowerShell
Need a hint?

Use $jsonOutput = ConvertTo-Json $employeeObj and then Write-Output $jsonOutput.