I need help to put the output from terminal in a csv file

Brian Oney brian.j.oney at googlemail.com
Fri Sep 7 10:17:44 EDT 2018


Please study the following to get you started. It looks like JSON output that you are dealing,
which is good. I added a ", to the "body"-line, because I assume that you botched that when giving
an example.

```python
#!/usr/bin/env python


import json


output = '''
{
   "error" : {
      "body" : "The requested device is currently not online.",
      "detail" : "Make sure to connect the device",
      "event" : 123456,
      "header" : "Device Unavailable (123456)"
   }
}
'''


# help(json.loads)
parsed = json.loads(output)

if type(parsed) == dict:
    if type(parsed['error']) == dict:
        print("yay!")
```

HTH


More information about the Python-list mailing list