git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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