Automation · Data Formats › JSON
Arrays
Cheat sheet · https://pcornel.dk/topic.php?topic=5820
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 lengthjq '.items[0]' file.json— first elementjq '[.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