@@ -28,13 +28,16 @@ shconfparser is a vendor independent library where you can parse the following f
2828- Table structure * ` i.e. show ip interface ` *
2929- Data * ` i.e. show version ` *
3030
31- YAML Format Output
31+ Modern Format (JSON/YAML) - Hierarchical Structure
3232
33- ![ show run to YAML structure] ( https://raw.githubusercontent.com/kirankotari/shconfparser/master/asserts/img/sh_run_yaml.png )
33+ ![ show run to modern YAML format structure] ( https://raw.githubusercontent.com/kirankotari/shconfparser/master/asserts/img/sh_run_yaml.png )
34+ <br />
35+ <br />
36+ ![ show run to modern JSON format structure] ( https://raw.githubusercontent.com/kirankotari/shconfparser/master/asserts/img/sh_run_json.png )
3437
35- Tree Structure
38+ Legacy Format - OrderedDict with Full Keys
3639
37- ![ show run to tree structure] ( https://raw.githubusercontent.com/kirankotari/shconfparser/master/asserts/img/sh_run.png )
40+ ![ show run to legacy format structure] ( https://raw.githubusercontent.com/kirankotari/shconfparser/master/asserts/img/sh_run.png )
3841
3942Table Structure
4043
@@ -67,12 +70,12 @@ uv pip install shconfparser
6770
6871### Basic Usage
6972
70- ** Single show command with YAML format (recommended ):**
73+ ** Modern format (recommended - hierarchical structure with XPath ):**
7174``` python
7275from shconfparser.parser import Parser
7376
74- # Use YAML format for cleaner output and XPath support
75- p = Parser(output_format = ' yaml ' )
77+ # Use modern format for cleaner output and XPath support
78+ p = Parser(output_format = ' json ' ) # or 'yaml'
7679data = p.read(' running_config.txt' )
7780
7881# Parse directly (no split needed for single show running command)
@@ -85,21 +88,24 @@ print(result.data) # 'R1'
8588```
8689
8790<details >
88- <summary >Alternative: JSON format (backward compatible)</summary >
91+ <summary >Alternative: Legacy format (backward compatible)</summary >
8992
9093``` python
91- p = Parser() # Default is JSON format (OrderedDict)
94+ p = Parser() # Defaults to 'legacy' format
95+ # or explicitly: Parser(output_format='legacy')
9296data = p.read(' running_config.txt' )
9397tree = p.parse_tree(data)
9498print (p.dump(tree, indent = 4 ))
99+ # Returns OrderedDict with full command strings as keys
100+ # Example: {'interface FastEthernet0/0': {...}}
95101```
96102</details >
97103
98104** Multiple show commands in one file:**
99105``` python
100106from shconfparser.parser import Parser
101107
102- p = Parser(output_format = ' yaml ' ) # YAML format recommended
108+ p = Parser(output_format = ' json ' ) # Modern format recommended
103109data = p.read(' multiple_commands.txt' ) # Contains multiple show outputs
104110data = p.split(data) # Split into separate commands
105111data.keys()
@@ -216,48 +222,47 @@ print(match)
216222# {'Device ID': 'R2', 'Local Intrfce': 'Fas 0/0', ...}
217223```
218224
219- ### Output Format Selection (New in 3.0!)
225+ ### Output Format Selection
220226
221- Parse configurations to JSON (OrderedDict) or YAML-friendly dict structures:
227+ Parse configurations in legacy (OrderedDict) or modern ( dict) hierarchical structures:
222228
223229``` python
224230from shconfparser.parser import Parser
225231
226- # Default: JSON format (OrderedDict - backward compatible)
227- p = Parser()
232+ # Legacy format (backward compatible - OrderedDict with full keys)
233+ p = Parser() # Defaults to 'legacy'
234+ # or explicitly: Parser(output_format='legacy')
228235data = p.read(' running_config.txt' )
229236tree = p.parse_tree(data) # Returns OrderedDict
230237print (type (tree)) # <class 'collections.OrderedDict'>
238+ # Example: {'interface FastEthernet0/0': {'ip address 1.1.1.1': ''}}
231239
232- # YAML format: cleaner hierarchical structure
233- p = Parser(output_format = ' yaml' )
240+ # Modern formats: JSON or YAML (hierarchical dict structure)
241+ p = Parser(output_format = ' json' ) # Hierarchical dict
242+ # or: Parser(output_format='yaml') # Same structure, different name
234243data = p.read(' running_config.txt' )
235- tree_yaml = p.parse_tree(data) # Returns dict with nested structure
236- print (type (tree_yaml)) # <class 'dict'>
244+ tree = p.parse_tree(data) # Returns dict
245+ print (type (tree)) # <class 'dict'>
246+ # Example: {'interface': {'FastEthernet0/0': {'ip': {'address': '1.1.1.1'}}}}
237247
238248# Override format per call
239- p = Parser() # Default is JSON
240- tree_json = p.parse_tree(data) # OrderedDict
241- tree_yaml = p.parse_tree(data, format = ' yaml' ) # dict
242-
243- # YAML structure example:
244- # Input: "interface FastEthernet0/0" with nested config
245- # JSON: {"interface FastEthernet0/0": {...}}
246- # YAML: {"interface": {"FastEthernet0/0": {...}}}
249+ p = Parser() # Legacy by default
250+ tree_legacy = p.parse_tree(data) # OrderedDict
251+ tree_json = p.parse_tree(data, format = ' json' ) # dict
247252```
248253
249254** Format Comparison:**
250255
251256``` python
252- # JSON format (default) - preserves exact CLI structure
257+ # Legacy format - preserves exact CLI structure (OrderedDict)
253258{
254259 " interface FastEthernet0/0" : {
255260 " ip address 1.1.1.1 255.255.255.0" : " " ,
256261 " duplex auto" : " "
257262 }
258263}
259264
260- # YAML format - hierarchical and human-readable
265+ # Modern formats (json/yaml) - hierarchical and programmatic (dict)
261266{
262267 " interface" : {
263268 " FastEthernet0/0" : {
@@ -270,12 +275,12 @@ tree_yaml = p.parse_tree(data, format='yaml') # dict
270275}
271276```
272277
273- ** Benefits of YAML format :**
278+ ** Benefits of modern formats (json/yaml) :**
274279- Cleaner hierarchy for nested configurations
275280- Better for programmatic access
276- - Easier to convert to actual YAML files
281+ - XPath query support
282+ - Easier to convert to actual JSON/YAML files
277283- Natural structure for complex configs
278- - Required for XPath queries
279284
280285### XPath Queries (New in 3.0!)
281286
0 commit comments