Skip to content

Commit e8debf2

Browse files
Bojun FengBojun-Feng
authored andcommitted
Fix invalid JSON output for 'show ip route <protocol> json' commands
Commands like 'show ip route bgp json' were producing invalid JSON with a namespace prefix (': '), breaking JSON parsers and automation. The issue occurred because protocol filters (bgp, static, etc.) triggered the namespace-prefix output path even when JSON was requested. On single-ASIC systems where namespace is empty, this resulted in ': ' being printed before the JSON output. Fixed by skipping the namespace-prefix path when JSON output is requested, allowing proper JSON processing and formatting. Signed-off-by: Bojun Feng <[email protected]>
1 parent 3994fcd commit e8debf2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

show/bgp_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def show_routes(args, namespace, display, verbose, ipver):
403403
return
404404

405405
# Multi-asic show ip route with additional parms are handled by going to FRR directly and get those outputs from each namespace
406-
if found_other_parms:
406+
if found_other_parms and not found_json:
407407
print("{}:".format(ns))
408408
print(output)
409409
continue
@@ -429,7 +429,7 @@ def show_routes(args, namespace, display, verbose, ipver):
429429
else:
430430
print_ip_routes(combined_route, filter_by_ip)
431431
else:
432-
new_string = json.dumps(combined_route,sort_keys=True, indent=4)
432+
new_string = json.dumps(combined_route, sort_keys=True, indent=4)
433433
print(new_string)
434434

435435
'''

0 commit comments

Comments
 (0)