Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Arrays

Direct 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.

When to use this

Use this when looping over JSON arrays in jq, PowerShell or Python and handling empty lists.

First 30 seconds

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.

Operational verification

[ values ] → iterate/filter

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
JSON parsing and validation
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformJSON parsing and validation · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when looping over JSON arrays in jq, PowerShell or Python and handling empty lists.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

1 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

observation · 1
Key points
  • Arrays are ordered lists in square brackets.
  • Iterate with .[] in jq or foreach in PowerShell.
  • Handle empty arrays explicitly.
Key checks
  • jq '.items | length' file.json — array length
  • jq '.items[0]' file.json — first element
  • jq '[.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
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docJSON parsing and validation current

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%
Confirmation

Confirm action

Continue?