resolvePath
Resolve dot/bracket notation paths against JSON values.
Signature
typescript
function resolvePath(
root: unknown,
path: string,
maxItems?: number
): ResolveResult | ResolveError;Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
root | unknown | — | The JSON value to resolve against |
path | string | — | Dot/bracket path (e.g. data.users[0].name) |
maxItems | number | 5 | Max elements to return for wildcard [*] paths |
Path Syntax
| Syntax | Description | Example |
|---|---|---|
key | Object key access | data.users |
[0] | Array index | data.users[0] |
[*] | Wildcard (all elements) | data.users[*].name |
Try it: Key and Index Access
Input
Output
Try it: Wildcards
Change the path to data.users[*].name to get all names. Try data.users[*].id for IDs.
Input
Output
Return Types
Success:
typescript
interface ResolveResult {
ok: true;
value: unknown;
isWildcard: boolean;
totalItems?: number; // for wildcard: total elements in array
}Error:
typescript
interface ResolveError {
ok: false;
error: string; // descriptive message with available keys
}Try it: Error Messages
Try paths that don't exist to see structured error messages. For example: data.missing or data.users[99].
Input
Output