Reading and Writing JSON to a File in Python

I am exploring the various forms of getting the output from a network devices mainly cisco_ios. I wanted to share the various ways which explore today. 

When I am running a script using NAPALM and use print function in python the output is something like showing below:

So I wanted the same output in the file which I am storing externally. I made some efforts and found below mentioned results:

Step1

Output: We get a text file but the output is not pretty good. so move to step 2.



Step2: To get output in same json format on which I am getting I try to save the file in ".json" format but there is no change in output.


Output:

Step3

Then I explore more from web and found json_dump function to get the desired output.

Output:

Output remains the same and no change found.😞


Step:4 I will not remain calm and search more in Internet and found concept of "Pretty Printing". I will not go into the details only wanted to share the command and output here so that I will not connection with the topic.

Output: 

Comments