Use this when looping over JSON arrays in jq, PowerShell or Python and handling empty lists.
Arrays
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.
1. Arrays are ordered lists.
2. Can mix types (avoid).
3. Iterate with .[] in jq.
4. Check length and emptiness.
5. Order matters for diffs.
[ values ] → iterate/filter
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Assuming an array always has at least one element.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Arrays are ordered lists in square brackets.
- Iterate with .[] in jq or foreach in PowerShell.
- Handle empty arrays explicitly.
jq '.items | length' file.json— array lengthjq '.items[0]' file.json— first elementjq '[.items[] | select(.enabled)]' file.json— filter
ReferenceWhy it matters1 section · depth on demand
What it is
A JSON array is an ordered list in [], possibly of mixed types.
ReferenceImportant terms & boundaries2 sections · depth on demand
How it works
Arrays preserve order and can contain any JSON values, including objects. Tools such as jq index with .[0], iterate with .[] and filter with select().
Example
{"dns_servers": ["10.0.0.53", "10.0.0.54"], "vlans": [{"id": 10}, {"id": 20}]}
jq '.vlans[].id' data.json
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in JSON > Arrays. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.rfc-editor.org/rfc/rfc8259 · confidence 94%