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

Function json_tree_value

src/mcp/compact_out.c:1133–1173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1131}
1132
1133static void json_tree_value(cbm_sb_t *sb, const char *key_name, size_t key_len, yyjson_val *value,
1134 int depth) {
1135 if (depth >= JSON_TREE_MAX_DEPTH) {
1136 json_tree_indent(sb, depth);
1137 append_key_n(sb, key_name, key_len);
1138 cbm_sb_append(sb, ": ");
1139 char *encoded = yyjson_val_write(value, 0, NULL);
1140 append_value(sb, encoded ? encoded : "null");
1141 free(encoded);
1142 cbm_sb_append_n(sb, "\n", 1);
1143 return;
1144 }
1145 if (yyjson_is_obj(value)) {
1146 json_tree_indent(sb, depth);
1147 append_key_n(sb, key_name, key_len);
1148 cbm_sb_append(sb, ":\n");
1149 size_t index;
1150 size_t maximum;
1151 yyjson_val *key;
1152 yyjson_val *child;
1153 yyjson_obj_foreach(value, index, maximum, key, child) {
1154 json_tree_value(sb, yyjson_get_str(key), yyjson_get_len(key), child, depth + 1);
1155 }
1156 } else if (yyjson_is_arr(value)) {
1157 json_tree_array(sb, key_name, key_len, value, depth);
1158 } else if (yyjson_is_str(value) &&
1159 !memchr(yyjson_get_str(value), '\0', yyjson_get_len(value)) &&
1160 (memchr(yyjson_get_str(value), '\n', yyjson_get_len(value)) ||
1161 memchr(yyjson_get_str(value), '\r', yyjson_get_len(value)))) {
1162 json_tree_indent(sb, depth);
1163 append_key_n(sb, key_name, key_len);
1164 cbm_sb_append(sb, ": ");
1165 json_tree_block_string(sb, yyjson_get_str(value), yyjson_get_len(value), depth);
1166 } else {
1167 json_tree_indent(sb, depth);
1168 append_key_n(sb, key_name, key_len);
1169 cbm_sb_append(sb, ": ");
1170 json_tree_scalar(sb, value);
1171 cbm_sb_append_n(sb, "\n", 1);
1172 }
1173}
1174
1175char *cbm_json_to_tree(const char *json) {
1176 if (!json) {

Callers 2

json_tree_arrayFunction · 0.85
cbm_json_to_treeFunction · 0.85

Calls 8

json_tree_indentFunction · 0.85
append_key_nFunction · 0.85
cbm_sb_appendFunction · 0.85
append_valueFunction · 0.85
cbm_sb_append_nFunction · 0.85
json_tree_arrayFunction · 0.85
json_tree_block_stringFunction · 0.85
json_tree_scalarFunction · 0.85

Tested by

no test coverage detected