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

Function updateJsonValue

packages/shell/src/extras.ts:52–82  ·  view source on GitHub ↗
(
  input: unknown,
  operations: StateJsonUpdateOperation[],
  filePath: string
)

Source from the content-addressed store, hash-verified

50}
51
52export function updateJsonValue(
53 input: unknown,
54 operations: StateJsonUpdateOperation[],
55 filePath: string
56): StateJsonUpdateResult {
57 const clone = structuredClone(input) as unknown;
58 for (const operation of operations) {
59 const tokens = parseJsonPath(operation.path);
60 if (operation.op === "set") {
61 setJsonPathValue(clone, tokens, operation.value);
62 } else {
63 deleteJsonPathValue(clone, tokens);
64 }
65 }
66
67 const content = JSON.stringify(clone, null, 2) + "\n";
68 return {
69 value: clone,
70 content,
71 diff:
72 JSON.stringify(input) === JSON.stringify(clone)
73 ? ""
74 : diffContent(
75 JSON.stringify(input, null, 2) + "\n",
76 content,
77 filePath,
78 filePath
79 ),
80 operationsApplied: operations.length
81 };
82}
83
84export async function buildTree(
85 root: string,

Callers 1

updateJsonMethod · 0.90

Calls 4

diffContentFunction · 0.90
parseJsonPathFunction · 0.85
setJsonPathValueFunction · 0.85
deleteJsonPathValueFunction · 0.85

Tested by

no test coverage detected