MCPcopy Create free account
hub / github.com/cloudflare/agents / queryJsonValue

Function queryJsonValue

packages/shell/src/extras.ts:33–50  ·  view source on GitHub ↗
(value: unknown, query: string)

Source from the content-addressed store, hash-verified

31};
32
33export 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
52export function updateJsonValue(
53 input: unknown,

Callers 1

queryJsonMethod · 0.90

Calls 1

parseJsonPathFunction · 0.85

Tested by

no test coverage detected