Parse array string¶
parseArrayString parses JSON‑compatible array strings into actual arrays.
It rejects any input that is not a syntactically valid array literal. If mode is set to strict or if the value is not a string, cannot be parsed as JSON, or does not produce an array, the rule emits no parse result.
Signature¶
Through the API:
.parse('array');
And internally:
export const parseArrayString: ParseRule<unknown>
(value: unknown, path: FieldPath) => ParseResult<unknown>[]
Events¶
| Event code | Description |
|---|---|
string.now.array |
Parsed string into a JSON array. |
Design rationale¶
- Accepts only syntactically valid JSON array literals.
- Rejects ambiguous or non‑array input without emitting events.
- Ensures contributors can rely on strict, predictable parsing behavior.
- Produces a single parse step containing the parsed array and one
parseEvent. - Never mutates or normalizes — parsing is a pure, opt‑in transformation.
Invoke¶
parseArrayString runs only when explicitly included in a boundary or pipeline.
It is not affected by normalization mode and does not run automatically.
The rule activates when:
- The value is a string.
- The string begins with
[and ends with]. - JSON parsing succeeds.
- The parsed value is an array.
Examples¶
Valid array string¶
const value = "[1, 2, 3]";
const result = parseArrayString(value, "$");
// → [
// {
// path: "$",
// nextValue: [1, 2, 3],
// events: [
// JaneEvent{ kind: "info", code: "string.now.array", ... }
// ]
// }
// ]
Invalid JSON — no parse¶
const result = parseArrayString("[1, 2,]", "$");
// → []
Non‑array JSON — no parse¶
const result = parseArrayString("{ x: 1 }", "$");
// → []
Non‑string value¶
const result = parseArrayString(42, "$");
// → []