MCPcopy Create free account
hub / github.com/Eversmile12/sharedcontext / readJsonObject

Function readJsonObject

src/cli/setup.ts:201–220  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

199}
200
201function readJsonObject(path: string): JsonObject {
202 if (!existsSync(path)) {
203 return {};
204 }
205
206 const raw = readFileSync(path, "utf-8").trim();
207 if (raw === "") {
208 return {};
209 }
210
211 try {
212 const parsed = JSON.parse(raw) as unknown;
213 if (!isJsonObject(parsed)) {
214 throw new Error("root value is not a JSON object");
215 }
216 return parsed;
217 } catch (err) {
218 throw new Error(`Invalid JSON in ${path}: ${toErrorMessage(err)}`);
219 }
220}
221
222function isJsonObject(value: unknown): value is JsonObject {
223 return typeof value === "object" && value !== null && !Array.isArray(value);

Callers 1

updateMcpConfigFunction · 0.85

Calls 2

isJsonObjectFunction · 0.85
toErrorMessageFunction · 0.85

Tested by

no test coverage detected