## TL;DR

The export's JSON nests deeper (or more irregularly) than the parser expects. Parse defensively: walk the structure with safe accessors, validate against a schema, and skip-and-log malformed records instead of aborting the run.

## Error

```text
agent failed to parse the expense export: nested json error
```

## Steps

1. Capture the failing JSON record and inspect its nesting. Expected: you see the unexpected depth or shape.
2. Replace direct key access with safe accessors that return a default on missing keys. Expected: missing fields no longer raise.
3. Add schema validation for the record shape you expect; log and skip records that fail validation. Expected: bad records are quarantined, good ones parse.
4. Handle the nesting generically: flatten known nested objects (line items, custom fields) into a uniform record. Expected: downstream code sees one shape.
5. Alert on the skip rate: a sudden spike means the export format changed. Expected: format drift pages someone instead of silently dropping data.

## When to use

- An agent errors parsing nested JSON expense exports.
- One malformed record kills the whole parse.

## When not to use

- The export is CSV with changed columns (see the format-change skill).
- The JSON is truncated mid-stream (see the truncated-JSON skill).

## Tool compatibility

- Custom agent ingest; JSON expense exports and APIs.

## Variant phrasings

### JSON parse error on expense export

Same failure, generic wording.

### Unexpected nesting in export data

Names the structural cause.

## Why it happens

Expense exports nest line items, custom fields, and audit trails to arbitrary depth, and vendors change the shape. Rigid parsers break on the first surprise; defensive parsers absorb it.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_dNyfCmHIg8pB2AcUeBYBgQ
