MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / read_json_file

Function read_json_file

src/cli/cli.c:722–755  ·  view source on GitHub ↗

Read a JSON file into a yyjson document. Returns NULL on error. */

Source from the content-addressed store, hash-verified

720
721/* Read a JSON file into a yyjson document. Returns NULL on error. */
722static yyjson_doc *read_json_file(const char *path) {
723 FILE *f = fopen(path, "r");
724 if (!f) {
725 return NULL;
726 }
727
728 (void)fseek(f, 0, SEEK_END);
729 long size = ftell(f);
730 (void)fseek(f, 0, SEEK_SET);
731
732 if (size <= 0 || size > (long)CLI_MB_10 * CLI_MB_FACTOR) {
733 (void)fclose(f);
734 return NULL;
735 }
736
737 char *buf = malloc((size_t)size + CLI_SKIP_ONE);
738 if (!buf) {
739 (void)fclose(f);
740 return NULL;
741 }
742
743 size_t nread = fread(buf, CLI_ELEM_SIZE, (size_t)size, f);
744 (void)fclose(f);
745 if (nread > (size_t)size) {
746 nread = (size_t)size;
747 }
748 buf[nread] = '\0';
749
750 /* Allow JSONC (comments + trailing commas) — Zed settings.json uses this format */
751 yyjson_read_flag flags = YYJSON_READ_ALLOW_COMMENTS | YYJSON_READ_ALLOW_TRAILING_COMMAS;
752 yyjson_doc *doc = yyjson_read(buf, nread, flags);
753 free(buf);
754 return doc;
755}
756
757/* Write a mutable yyjson document to a file with pretty printing. */
758static int write_json_file(const char *path, yyjson_mut_doc *doc) {

Callers 12

cbm_install_editor_mcpFunction · 0.85
cbm_remove_editor_mcpFunction · 0.85
cbm_install_openclaw_mcpFunction · 0.85
cbm_remove_openclaw_mcpFunction · 0.85
cbm_install_vscode_mcpFunction · 0.85
cbm_remove_vscode_mcpFunction · 0.85
cbm_install_zed_mcpFunction · 0.85
cbm_remove_zed_mcpFunction · 0.85
cbm_upsert_opencode_mcpFunction · 0.85
cbm_remove_opencode_mcpFunction · 0.85
upsert_hooks_jsonFunction · 0.85
remove_hooks_jsonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected