0
0
PowerShellscripting~20 mins

JSON operations (ConvertFrom-Json, ConvertTo-Json) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JSON Mastery in PowerShell
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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.name
A{name=Alice; age=30}
BAlice
C30
DSystem.Object
Attempts:
2 left
💡 Hint
ConvertFrom-Json turns JSON text into an object you can access properties from.
💻 Command Output
intermediate
2:00remaining
What does this command output?
What is the output of this PowerShell command?
PowerShell
$obj = @{name='Bob'; age=25}; $json = $obj | ConvertTo-Json; $json
A
{
  "name": "Bob",
  "age": 25
}
Bname=Bob age=25
CSystem.String
D{"name":"Bob","age":25}
Attempts:
2 left
💡 Hint
ConvertTo-Json formats the object as a JSON string with indentation.
📝 Syntax
advanced
2: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"}}}';
A$obj = ConvertFrom-Json $json; $obj.person.address.city
B$obj = $json | ConvertFrom-Json; $obj['person']['address']['city']
C$obj = $json | ConvertFrom-Json; $obj.person.address.city
D$obj = $json | ConvertTo-Json; $obj.person.address.city
Attempts:
2 left
💡 Hint
ConvertFrom-Json converts JSON text to an object. Use dot notation to access nested properties.
🔧 Debug
advanced
2: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 $obj
AThe command outputs JSON but it is not captured or printed explicitly.
BConvertTo-Json cannot convert hashtables directly.
CThe variable $obj is empty, so no output is produced.
DConvertTo-Json requires the -Compress flag to output anything.
Attempts:
2 left
💡 Hint
In PowerShell, commands output to the pipeline but may not display if not captured or printed.
🚀 Application
expert
2: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.Count
AThrows an error
B1
C0
D3
Attempts:
2 left
💡 Hint
ConvertFrom-Json converts JSON arrays into PowerShell arrays with Count property.