Pcornel
Automation · Data Formats › JSON

Parsing

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

Back to the Topic

Answer

Parse JSON with built-in tools — jq on the command line, ConvertFrom-Json in PowerShell, json.loads in Python — and handle errors when the input is not valid JSON.

Remember

  • Use jq, ConvertFrom-Json or json.loads.
  • Catch parse errors on invalid input.
  • PowerShell ConvertTo-Json needs -Depth for nested data.

First checks

  • jq -e . file.json >/dev/null && echo valid — parse check
  • python3 -c 'import json;json.load(open("f.json"))' — Python parse
  • ConvertFrom-Json (PowerShell) — parse

Verify in this order

text → JSON parser → objects or error

Where it usually breaks

Client payload/auth → HTTP transport → endpoint validation/policy → request accepted → queued/job execution → target mutation → effective state → consumer workload.

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

Confirmation

Confirm action

Continue?