Skip to content

Commit

Permalink
improve output
Browse files Browse the repository at this point in the history
less crashing, more output
  • Loading branch information
flowerysong committed Jun 4, 2024
1 parent 82bf0f6 commit e265da8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ejq.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ static void
raw_print(json *obj) {
json *arr = NULL;

if (obj == NULL) {
return;
}

switch (obj->type) {
case JSON_STRING:
printf("%s\n", obj->str);
Expand All @@ -50,7 +54,8 @@ raw_print(json *obj) {
break;

default:
/* Nothing to do. */
/* just the normal repr */
printf("%s\n", jsonToString(obj, NULL));
break;
}
}
Expand Down Expand Up @@ -98,15 +103,17 @@ main(int ac, char *av[]) {
* structure, to easily only output the selected bit we need to throw
* away the key and the following elements (if any).
*/
res->key = NULL;
res->next = NULL;
if (res) {
res->key = NULL;
res->next = NULL;
}
} else {
res = parsed;
}

if (raw) {
raw_print(res);
} else {
printf("%s", jsonToString(res, NULL));
printf("%s\n", jsonToString(res, NULL));
}
}

0 comments on commit e265da8

Please sign in to comment.