Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Parsing · JSON

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

When to use this

Use this when parsing JSON safely in jq, PowerShell or Python with error handling.

First 30 seconds

1. Parse with real JSON parsers.

2. Handle errors (invalid JSON).

3. Watch encoding (BOM).

4. Stream large files.

5. Never eval JSON.

Operational verification

text → JSON parser → objects or error

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 parsing JSON safely in jq, PowerShell or Python with error handling.
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.

2 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 Verification path Verify boundary

The negative fixture should deliberately exercise risks such as encoding/BOM issues, delimiter/quoting ambiguity, duplicate keys, namespace drift, scalar coercion, invalid schema assumptions and parser success without consumer-valid semantics, choosing the cases most relevant to decoding/lexing/structural parse, schema validation, error location and preventing parser success from being treated as business-semantic validity.

Step 2 Common mistakes Narrow the fault
  • Parsing HTML error pages as JSON.
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
  • Use jq, ConvertFrom-Json or json.loads.
  • Catch parse errors on invalid input.
  • PowerShell ConvertTo-Json needs -Depth for nested data.
Key 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
ReferenceWhy it matters1 section · depth on demand

What it is

Parsing turns JSON text into native structures; handle errors and missing keys.

ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

Parsing JSON turns text into native data structures so a script can work with the values. Every major language has a built-in parser; on the command line jq is the standard tool.

import json
data = json.loads(text)                 # str → dict/list
with open("devices.json") as f: devices = json.load(f)
json.dumps(data, indent=2, sort_keys=True)
$data = Get-Content devices.json -Raw | ConvertFrom-Json
$data | ConvertTo-Json -Depth 10        # default depth is 2 — set it explicitly
jq -r '.results[] | [.name, .site.name] | @tsv' devices.json

Handle parse errors explicitly (json.JSONDecodeError) — an HTML error page from an API is a common reason JSON parsing fails.

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 > Parsing. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.rfc-editor.org/rfc/rfc8259 · confidence 94%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For decoding/lexing/structural parse, schema validation, error location and preventing parser success from being treated as business-semantic validity, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?