Bird
0
0

What will be the output of this code?

medium📝 Command Output Q5 of 15
PowerShell - File and Directory Operations
What will be the output of this code?
$obj = @{name='Eve'; age=28}
$json = $obj | ConvertTo-Json
$json
A{"name":"Eve","age":28}
B@{name=Eve; age=28}
Cname: Eve, age: 28
DError: Cannot convert object
Step-by-Step Solution
Solution:
  1. Step 1: Create a hashtable object

    The variable $obj is a hashtable with keys name and age.
  2. Step 2: Convert object to JSON string

    Using ConvertTo-Json converts the hashtable to a JSON string with double quotes and braces.
  3. Final Answer:

    {"name":"Eve","age":28} -> Option A
  4. Quick Check:

    ConvertTo-Json outputs JSON string with quotes [OK]
Quick Trick: ConvertTo-Json outputs JSON string with quotes and braces [OK]
Common Mistakes:
  • Expecting PowerShell object format as output
  • Confusing JSON string with object display
  • Assuming conversion fails

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes