MCPcopy Index your code
hub / github.com/modelcontextprotocol/inspector / updateObject

Function updateObject

client/src/utils/jsonUtils.ts:189–214  ·  view source on GitHub ↗

* Updates an object at a specific path

(
  obj: JsonObject,
  path: string[],
  value: JsonValue,
)

Source from the content-addressed store, hash-verified

187 * Updates an object at a specific path
188 */
189function updateObject(
190 obj: JsonObject,
191 path: string[],
192 value: JsonValue,
193): JsonObject {
194 const [key, ...restPath] = path;
195
196 // Validate object key
197 if (typeof key !== "string") {
198 console.error(`Invalid object key: ${key}`);
199 return obj;
200 }
201
202 const newObj = { ...obj };
203
204 if (restPath.length === 0) {
205 newObj[key] = value;
206 } else {
207 // Ensure key exists
208 if (!(key in newObj)) {
209 newObj[key] = {};
210 }
211 newObj[key] = updateValueAtPath(newObj[key], restPath, value);
212 }
213 return newObj;
214}
215
216/**
217 * Gets a value at a specific path in a nested JSON structure

Callers 1

updateValueAtPathFunction · 0.85

Calls 1

updateValueAtPathFunction · 0.85

Tested by

no test coverage detected