Challenge - 5 Problems
JSON Mastery in PowerShell
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell command?
Given this JSON string and command, what will be the output?
PowerShell
$json = '{"name":"Alice","age":30}'; $obj = $json | ConvertFrom-Json; $obj.nameAttempts:
2 left
💡 Hint
ConvertFrom-Json turns JSON text into an object you can access properties from.
✗ Incorrect
The ConvertFrom-Json cmdlet converts the JSON string into an object. Accessing $obj.name returns the string 'Alice'.
💻 Command Output
intermediate2:00remaining
What does this command output?
What is the output of this PowerShell command?
PowerShell
$obj = @{name='Bob'; age=25}; $json = $obj | ConvertTo-Json; $jsonAttempts:
2 left
💡 Hint
ConvertTo-Json formats the object as a JSON string with indentation.
✗ Incorrect
ConvertTo-Json outputs a formatted JSON string with properties and values. It includes indentation and quotes.
📝 Syntax
advanced2:00remaining
Which option correctly parses nested JSON and accesses a nested property?
Given this JSON string, which command correctly outputs the city name?
PowerShell
$json = '{"person":{"name":"Eve","address":{"city":"Seattle","zip":"98101"}}}';Attempts:
2 left
💡 Hint
ConvertFrom-Json converts JSON text to an object. Use dot notation to access nested properties.
✗ Incorrect
Option C correctly pipes the JSON string to ConvertFrom-Json and accesses nested properties with dots. Option C is invalid syntax. Option C uses ConvertTo-Json which converts objects to JSON, not parsing. Option C uses array syntax which is invalid for PSCustomObject.
🔧 Debug
advanced2:00remaining
Why does this command fail to output the expected JSON string?
This PowerShell code is intended to convert an object to JSON and print it, but it outputs nothing. What is the problem?
PowerShell
$obj = @{fruit='apple'; color='red'}; ConvertTo-Json $objAttempts:
2 left
💡 Hint
In PowerShell, commands output to the pipeline but may not display if not captured or printed.
✗ Incorrect
ConvertTo-Json outputs JSON to the pipeline, but if the output is not assigned or printed, it may not appear. Using Write-Output or assigning to a variable and then printing fixes this.
🚀 Application
expert2:00remaining
How many items are in the resulting array after this JSON conversion?
Given this JSON string representing an array, how many elements does the PowerShell object contain after conversion?
PowerShell
$json = '[{"id":1,"val":"a"},{"id":2,"val":"b"},{"id":3,"val":"c"}]'; $arr = $json | ConvertFrom-Json; $arr.CountAttempts:
2 left
💡 Hint
ConvertFrom-Json converts JSON arrays into PowerShell arrays with Count property.
✗ Incorrect
The JSON string is an array of 3 objects. After conversion, $arr is a PowerShell array with 3 elements, so $arr.Count is 3.