Bird
0
0

Why does this code produce an error?

medium📝 Debug Q7 of 15
PowerShell - File and Directory Operations
Why does this code produce an error?
$json = '{name:"Anna",age:22}'
$obj = ConvertFrom-Json $json
AMissing ConvertTo-Json before ConvertFrom-Json
BConvertFrom-Json cannot parse numbers
CJSON keys must be in double quotes
DVariable $json is not defined
Step-by-Step Solution
Solution:
  1. Step 1: Check JSON syntax

    JSON requires keys to be in double quotes, but here keys are unquoted.
  2. Step 2: Understand ConvertFrom-Json parsing

    ConvertFrom-Json expects valid JSON syntax, so it fails on invalid keys.
  3. Final Answer:

    JSON keys must be in double quotes -> Option C
  4. Quick Check:

    Valid JSON keys need double quotes [OK]
Quick Trick: Always quote JSON keys with double quotes [OK]
Common Mistakes:
  • Using single quotes or no quotes for keys
  • Assuming ConvertFrom-Json fixes invalid JSON
  • Confusing ConvertTo-Json usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes