Bird
0
0

You have a PowerShell object:

hard📝 Application Q15 of 15
PowerShell - File and Directory Operations
You have a PowerShell object:
$person = @{ Name = "Eve"; Age = 28; Skills = @("PowerShell", "JSON") }

Which command correctly converts this object to JSON text with indentation for readability?
A$person | ConvertTo-Json -Depth 2 -Compress
B$person | ConvertTo-Json -Depth 2 -Pretty
C$person | ConvertTo-Json -Depth 2
DConvertTo-Json $person -Depth 2 -Compress
Step-by-Step Solution
Solution:
  1. Step 1: Understand ConvertTo-Json parameters

    ConvertTo-Json converts objects to JSON text. The -Depth parameter controls how deep nested objects are converted.
  2. Step 2: Identify correct parameter for indentation

    By default, ConvertTo-Json outputs indented JSON. The -Compress parameter removes whitespace, so it is not desired. There is no -Pretty parameter.
  3. Final Answer:

    $person | ConvertTo-Json -Depth 2 -> Option C
  4. Quick Check:

    Default output is indented JSON [OK]
Quick Trick: Use ConvertTo-Json with -Depth; default output is indented [OK]
Common Mistakes:
  • Using -Compress removes indentation
  • Using non-existent -Pretty parameter
  • Not setting -Depth for nested objects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes