MCPcopy Create free account
hub / github.com/ElementsProject/lightning / print_json

Function print_json

cli/lightning-cli.c:320–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

318}
319
320static void print_json(const char *str, const jsmntok_t *tok, const char *indent)
321{
322 size_t i;
323 const jsmntok_t *t;
324 bool first;
325 char next_indent[strlen(indent) + 3 + 1];
326
327 memset(next_indent, ' ', sizeof(next_indent)-1);
328 next_indent[sizeof(next_indent)-1] = '\0';
329
330 switch (tok->type) {
331 case JSMN_PRIMITIVE:
332 case JSMN_STRING:
333 printf("%.*s", json_tok_full_len(tok), json_tok_full(str, tok));
334 return;
335
336 case JSMN_ARRAY:
337 first = true;
338 json_for_each_arr(i, t, tok) {
339 if (first)
340 printf("[\n%s", next_indent);
341 else
342 printf(",\n%s", next_indent);
343 print_json(str, t, next_indent);
344 first = false;
345 }
346 if (first)
347 printf("[]");
348 else
349 printf("\n%s]", indent);
350 return;
351
352 case JSMN_OBJECT:
353 first = true;
354 json_for_each_obj(i, t, tok) {
355 if (first)
356 printf("{\n%s", next_indent);
357 else
358 printf(",\n%s", next_indent);
359 print_json(str, t, next_indent);
360 printf(": ");
361 print_json(str, t + 1, next_indent);
362 first = false;
363 }
364 if (first)
365 printf("{}");
366 else
367 printf("\n%s}", indent);
368 return;
369 case JSMN_UNDEFINED:
370 break;
371 }
372 abort();
373}
374
375/* Always returns a positive number < len. len must be > 0! */
376static size_t read_nofail(int fd, void *buf, size_t len)

Callers 1

mainFunction · 0.85

Calls 3

abortFunction · 0.85
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected