Pcornel
Automation · Data Formats › JSON

Arrays

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

Back to the Topic

Answer

JSON arrays are ordered lists in square brackets, such as ["web01", "web02"]. Loop over them in jq with .[] or in PowerShell with foreach, and check for empty arrays.

Remember

  • Arrays are ordered lists in square brackets.
  • Iterate with .[] in jq or foreach in PowerShell.
  • Handle empty arrays explicitly.

First checks

  • jq '.items | length' file.json — array length
  • jq '.items[0]' file.json — first element
  • jq '[.items[] | select(.enabled)]' file.json — filter

Verify in this order

[ values ] → iterate/filter

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=5820

Confirmation

Confirm action

Continue?