When JunOS CLI output is collected using 'show <command> | display json' and further parsed using standard JSON parsing tools, the result may be unexpected.
For example when CLI output in JSON format is collected:
user@router> show mvpn neighbor summary | display json { "mvpn-instance-information" : [ { "attributes" : {"xmlns" : "http://xml.juniper.net/junos/24.1I0/junos-routing"}, "mvpn-instance" : [ { "attributes" : {"junos:style" : "summary"}, "instance-family" : [ { "address-family" : [ { "data" : "INET" } ], "instance-entry" : [ { "instance-name" : [ { "data" : "MVPN-1" } ], "ngen-mvpn-mode" : [ { "data" : "SPT-ONLY" } ] } ], "instance-entry-summary" : [ { "neighbor-summary" : [ { "neighbor-summary-count" : [ { "data" : "2" } ] } ] } ], "instance-entry" : [ { "instance-name" : [ { "data" : "MVPN-2" } ], "ngen-mvpn-mode" : [ { "data" : "SPT-ONLY" } ] } ], "instance-entry-summary" : [ { } ] }, { "address-family" : [ { "data" : "INET6" } ], "instance-entry" : [ { "instance-name" : [ { "data" : "MVPN-1" } ], "ngen-mvpn-mode" : [ { "data" : "SPT-ONLY" } ] } ], "instance-entry-summary" : [ { } ], "instance-entry" : [ { "instance-name" : [ { "data" : "MVPN-2" } ], "ngen-mvpn-mode" : [ { "data" : "SPT-ONLY" } ] } ], "instance-entry-summary" : [ { } ] } ] } ] } ] }
is parsed by standard JSON parser the only last instance/instance-summary data is present
{'attributes': {'xmlns': 'http://xml.juniper.net/junos/24.1I0/junos-routing'}, 'mvpn-instance': [{'attributes': {'junos:style': 'summary'}, ' instance-family': [{'address-family': [{'data': 'INET'}], 'instance-entry': [{'instance-name': [{'data': 'MVPN-2'}], <<< only last MVPN instance MVPN-2 is present 'ngen-mvpn-mode': [{'data': 'SPT-ONLY'}]}], 'instance-entry-summary': [{}]}, {'address-family': [{'data': 'INET6'}], 'instance-entry': [{'instance-name': [{'data': 'MVPN-2'}], 'ngen-mvpn-mode': [{'data': 'SPT-ONLY'}]}], 'instance-entry-summary': [{}]}]}]}
The described above behaviour happens due to using standard JSON parser tool to parse JunOS0specific JSON data representations. In Junos, the JSON data for CLI is achieved by converting respective CLI XML output data into JSON format. JunOS has own convention of mapping XML data into JSON which is not same as per standard XML to JSON conversions.
If parsing JSON representation of JunOS CLI output is required, please use the following approach:
Get JunOS CLI output in XML using show <command> | display xml no-export-path
Convert this output into JSON format using any standard tool
Parse obtained JSON output using standard JSON parsing tools
2024-11-20: Minor writing modification2024-03-05 : Article Created