Python Forum
CiscoConfParse to json output
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CiscoConfParse to json output
#2
You need to insert some initialization of your dict before loop in line # 39:
The code should look like the following:

# ....
result["interfaces"][intf_name].update({
                  "address": "n/a",
                  "netmask": "n/a",
                  "network": "n/a"
            })

for cmd in interface_cmd.re_search_children(IPv4_REGEX):
            # ciscoconfparse provides a helper function for this task
            ipv4_addr = interface_cmd.re_match_iter_typed(IPv4_REGEX, result_type=IPv4Obj)
 
            result["interfaces"][intf_name].update({
                  "address": ipv4_addr.ip.exploded,
                  "netmask": ipv4_addr.netmask.exploded,
                  "network": ipv4_addr.network.exploded
            })
# ...
Reply


Messages In This Thread
CiscoConfParse to json output - by anna - Feb-06-2019, 01:35 PM
RE: CiscoConfParse to json output - by scidam - Feb-07-2019, 12:13 PM
RE: CiscoConfParse to json output - by anna - Feb-07-2019, 04:26 PM
RE: CiscoConfParse to json output - by anna - Feb-08-2019, 12:20 PM
RE: CiscoConfParse to json output - by scidam - Feb-09-2019, 11:45 AM
RE: CiscoConfParse to json output - by anna - Feb-09-2019, 05:18 PM
RE: CiscoConfParse to json output - by anna - Feb-12-2019, 10:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  geojson to json --missing multiple row output yoshi 9 2,818 Mar-06-2022, 08:34 PM
Last Post: snippsat
  json.dumps list output qurr 12 5,293 Apr-08-2020, 10:13 PM
Last Post: micseydel
  json.dumps output error in python3 prayuktibid 2 2,683 Jan-21-2020, 06:41 AM
Last Post: prayuktibid
  Output to a json file problem Netcode 3 3,752 Nov-22-2019, 01:44 AM
Last Post: Skaperen
  Make a table from a json output carstenlp 13 25,979 Jan-12-2019, 09:06 PM
Last Post: carstenlp
  Unable to parse JSON output dragan979 1 3,567 Apr-20-2018, 02:24 PM
Last Post: dragan979

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020