Skip to content

Commit 8aa559b

Browse files
committed
PGPRO-533: Reformat json output
1 parent 733354c commit 8aa559b

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/show.c

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,8 @@ show_instance_start(void)
234234
first_instance = true;
235235
json_level = 0;
236236

237-
json_add(&show_buf, JT_BEGIN_OBJECT);
238-
json_add_key(&show_buf, "instances", false);
239-
json_add(&show_buf, JT_BEGIN_ARRAY);
237+
appendPQExpBufferChar(&show_buf, '[');
238+
json_level++;
240239
}
241240

242241
/*
@@ -246,11 +245,7 @@ static void
246245
show_instance_end(void)
247246
{
248247
if (show_format == SHOW_JSON)
249-
{
250-
json_add(&show_buf, JT_END_ARRAY);
251-
json_add(&show_buf, JT_END_OBJECT);
252-
appendPQExpBufferChar(&show_buf, '\n');
253-
}
248+
appendPQExpBufferStr(&show_buf, "\n]\n");
254249

255250
fputs(show_buf.data, stdout);
256251
termPQExpBuffer(&show_buf);
@@ -505,10 +500,9 @@ show_instance_json(parray *backup_list)
505500

506501
/* Begin of instance object */
507502
json_add(buf, JT_BEGIN_OBJECT);
508-
json_add_key(buf, instance_name, false);
509503

510-
json_add(buf, JT_BEGIN_OBJECT);
511-
json_add_key(buf, "backups", false);
504+
json_add_value(buf, "instance", instance_name, false);
505+
json_add_key(buf, "backups", true);
512506

513507
/*
514508
* List backups.
@@ -528,19 +522,14 @@ show_instance_json(parray *backup_list)
528522
appendPQExpBufferChar(buf, ',');
529523

530524
json_add(buf, JT_BEGIN_OBJECT);
531-
json_add_key(buf, base36enc(backup->start_time), false);
532525

533-
/* Show backup attributes */
534-
json_add(buf, JT_BEGIN_OBJECT);
526+
json_add_value(buf, "id", base36enc(backup->start_time), false);
535527

536528
if (backup->parent_backup != 0)
537-
{
538529
json_add_value(buf, "parent-backup-id",
539-
base36enc(backup->parent_backup), false);
540-
json_add_value(buf, "backup-mode", pgBackupGetBackupMode(backup), true);
541-
}
542-
else
543-
json_add_value(buf, "backup-mode", pgBackupGetBackupMode(backup), false);
530+
base36enc(backup->parent_backup), true);
531+
532+
json_add_value(buf, "backup-mode", pgBackupGetBackupMode(backup), true);
544533

545534
json_add_value(buf, "wal", backup->stream ? "STREAM": "ARCHIVE", true);
546535

@@ -612,15 +601,11 @@ show_instance_json(parray *backup_list)
612601

613602
json_add_value(buf, "status", status2str(backup->status), true);
614603

615-
json_add(buf, JT_END_OBJECT);
616-
/* End of backup attributes */
617-
618604
json_add(buf, JT_END_OBJECT);
619605
}
620606

621607
/* End of backups */
622608
json_add(buf, JT_END_ARRAY);
623-
json_add(buf, JT_END_OBJECT);
624609

625610
/* End of instance object */
626611
json_add(buf, JT_END_OBJECT);

0 commit comments

Comments
 (0)