pretty-print json to terminal

This commit is contained in:
Emma Tebibyte 2023-06-15 13:31:27 -06:00
parent b78e4b0971
commit 299ac1f200
Signed by: emma
GPG Key ID: 6D661C738815E7DD

View File

@ -82,11 +82,14 @@ curl_read_data_t search(char *argv[], char *term) {
}
void parse_json(char *argv[], char* json) {
int out;
char *parsed_json;
json_error_t *error;
char *pretty_print;
json_t *json_val = json_loads(json, JSON_DECODE_ANY, error);
out = json_unpack(json_val, "{s:o}");
json_unpack(json_val, "{s:o}", parsed_json);
pretty_print = json_dumps(json_val, JSON_INDENT(2));
printf("%s\n", pretty_print);
}
int main(int argc, char *argv[]) {
@ -99,7 +102,6 @@ int main(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
json = search(argv, argv[i]);
write(1, json.data, json.len);
parse_json(argv, json.data);
}
return EX_OK;