@@ -26,6 +26,21 @@ static int show_backup(time_t requested_backup_id);
26
26
static void show_instance_plain (parray * backup_list , bool show_name );
27
27
static void show_instance_json (parray * backup_list );
28
28
29
+ /* Json output functions */
30
+
31
+ typedef enum
32
+ {
33
+ JT_BEGIN_ARRAY ,
34
+ JT_END_ARRAY ,
35
+ JT_BEGIN_OBJECT ,
36
+ JT_END_OBJECT
37
+ } JsonToken ;
38
+
39
+ static void json_add (PQExpBuffer buf , JsonToken type );
40
+ static void json_add_key (PQExpBuffer buf , const char * name , bool add_comma );
41
+ static void json_add_value (PQExpBuffer buf , const char * name , const char * value ,
42
+ bool add_comma );
43
+
29
44
static PQExpBufferData show_buf ;
30
45
static bool first_instance = true;
31
46
static uint8 json_level = 0 ;
@@ -219,8 +234,9 @@ show_instance_start(void)
219
234
first_instance = true;
220
235
json_level = 0 ;
221
236
222
- appendPQExpBufferChar (& show_buf , '[' );
223
- json_level ++ ;
237
+ json_add (& show_buf , JT_BEGIN_OBJECT );
238
+ json_add_key (& show_buf , "instances" , false);
239
+ json_add (& show_buf , JT_BEGIN_ARRAY );
224
240
}
225
241
226
242
/*
@@ -230,7 +246,11 @@ static void
230
246
show_instance_end (void )
231
247
{
232
248
if (show_format == SHOW_JSON )
233
- appendPQExpBufferStr (& show_buf , "\n]\n" );
249
+ {
250
+ json_add (& show_buf , JT_END_ARRAY );
251
+ json_add (& show_buf , JT_END_OBJECT );
252
+ appendPQExpBufferChar (& show_buf , '\n' );
253
+ }
234
254
235
255
fputs (show_buf .data , stdout );
236
256
termPQExpBuffer (& show_buf );
@@ -375,14 +395,6 @@ json_add_indent(PQExpBuffer buf)
375
395
appendPQExpBufferStr (buf , " " );
376
396
}
377
397
378
- typedef enum
379
- {
380
- JT_BEGIN_ARRAY ,
381
- JT_END_ARRAY ,
382
- JT_BEGIN_OBJECT ,
383
- JT_END_OBJECT
384
- } JsonToken ;
385
-
386
398
static void
387
399
json_add (PQExpBuffer buf , JsonToken type )
388
400
{
@@ -493,10 +505,10 @@ show_instance_json(parray *backup_list)
493
505
494
506
/* Begin of instance object */
495
507
json_add (buf , JT_BEGIN_OBJECT );
508
+ json_add_key (buf , instance_name , false);
496
509
497
- json_add_value (buf , "instance" , instance_name , false);
498
-
499
- json_add_key (buf , "backups" , true);
510
+ json_add (buf , JT_BEGIN_OBJECT );
511
+ json_add_key (buf , "backups" , false);
500
512
501
513
/*
502
514
* List backups.
@@ -516,14 +528,19 @@ show_instance_json(parray *backup_list)
516
528
appendPQExpBufferChar (buf , ',' );
517
529
518
530
json_add (buf , JT_BEGIN_OBJECT );
531
+ json_add_key (buf , base36enc (backup -> start_time ), false);
519
532
520
- json_add_value (buf , "id" , base36enc (backup -> start_time ), false);
533
+ /* Show backup attributes */
534
+ json_add (buf , JT_BEGIN_OBJECT );
521
535
522
536
if (backup -> parent_backup != 0 )
537
+ {
523
538
json_add_value (buf , "parent-backup-id" ,
524
- base36enc (backup -> parent_backup ), true);
525
-
526
- json_add_value (buf , "backup-mode" , pgBackupGetBackupMode (backup ), true);
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);
527
544
528
545
json_add_value (buf , "wal" , backup -> stream ? "STREAM" : "ARCHIVE" , true);
529
546
@@ -545,6 +562,7 @@ show_instance_json(parray *backup_list)
545
562
json_add_key (buf , "checksum-version" , true);
546
563
appendPQExpBuffer (buf , "%u" , backup -> checksum_version );
547
564
565
+ json_add_value (buf , "program-version" , backup -> program_version , true);
548
566
json_add_value (buf , "server-version" , backup -> server_version , true);
549
567
550
568
json_add_key (buf , "current-tli" , true);
@@ -594,11 +612,15 @@ show_instance_json(parray *backup_list)
594
612
595
613
json_add_value (buf , "status" , status2str (backup -> status ), true);
596
614
615
+ json_add (buf , JT_END_OBJECT );
616
+ /* End of backup attributes */
617
+
597
618
json_add (buf , JT_END_OBJECT );
598
619
}
599
620
600
621
/* End of backups */
601
622
json_add (buf , JT_END_ARRAY );
623
+ json_add (buf , JT_END_OBJECT );
602
624
603
625
/* End of instance object */
604
626
json_add (buf , JT_END_OBJECT );
0 commit comments