(value: unknown, query: string)
| 31 | }; |
| 32 | |
| 33 | export function queryJsonValue(value: unknown, query: string): unknown { |
| 34 | const tokens = parseJsonPath(query); |
| 35 | let current = value; |
| 36 | for (const token of tokens) { |
| 37 | if (typeof token === "number") { |
| 38 | if (!Array.isArray(current)) { |
| 39 | throw new Error(`JSON query expected array access at [${token}]`); |
| 40 | } |
| 41 | current = current[token]; |
| 42 | } else { |
| 43 | if (current === null || typeof current !== "object") { |
| 44 | throw new Error(`JSON query expected object access at "${token}"`); |
| 45 | } |
| 46 | current = (current as Record<string, unknown>)[token]; |
| 47 | } |
| 48 | } |
| 49 | return current; |
| 50 | } |
| 51 | |
| 52 | export function updateJsonValue( |
| 53 | input: unknown, |
no test coverage detected