Pcornel
Automation · PowerShell Automation

JSON

Cheat sheet · https://pcornel.dk/topic.php?topic=5251

Back to the Topic

Answer

PowerShell handles JSON with ConvertFrom-Json to turn text into objects and ConvertTo-Json -Depth to serialize, since the default depth of 2 silently truncates nested data.

Remember

  • ConvertFrom-Json turns text into objects.
  • ConvertTo-Json -Depth avoids truncation.
  • Default depth of 2 silently cuts nested data.

First checks

  • Get-Content f.json -Raw | ConvertFrom-Json — parse
  • $obj | ConvertTo-Json -Depth 10 — serialise
  • Test-Json -Json $json -Schema $schema — validate (PS 7)

Verify in this order

JSON ↔ PowerShell objects

Where it usually breaks

Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.

JSON · PowerShell operational reference

BoundaryJSON reference
Runtime identityPowerShell edition/version + command/module source
Persistent intentScript/module/config prerequisites under source control
VerificationRead-only discovery → execution evidence → independent target read-back
Output contractStructured objects/streams before formatting
Failure boundarySeparate engine/binding from transport/API/native and target-state failures

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5251

Confirmation

Confirm action

Continue?