Androtex
Androtex

Reputation: 31

Nicer looking output in the terminal Visual Studio Code

Is there any way to make the output in the Visual Studio Code Python terminal more readable?

This is what the terminal looks like after scraping information from my Twitch channel:

{"docs":[{"donation":{"user":{"username":"Mrrobotsan","geo":"SE","email":"[email protected]"},"media":{"start":0,"videoId":""},"message":"Sorry for delayed dono, but you truly are the most beautiful streamer 
in da wolrdo... with very sexy haircut, pls send dm ;D","amount":5,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5f5fbc48d8f39ac6c71397f6","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-09-14T18:54:00.526Z","updatedAt":"2020-09-14T18:54:12.992Z","token":"EC-41X07702TH3551025","transactionId":"6U238320601573020"},{"donation":{"user":{"username":"Mrrobotsan","geo":"SE","email":"[email protected]"},"media":{"start":0,"videoId":""},"message":"Sorry for delay best streamer, with very sexy haircut, send dm pls ;D","amount":5,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5f5fbb8cf2b37c417bb01c3d","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-09-14T18:50:52.318Z","updatedAt":"2020-09-14T18:53:05.455Z","token":"EC-8UL51613AG332564X","transactionId":"22865708CK4171210"},{"donation":{"user":{"username":"teusz","geo":"SE","email":"[email protected]"},"media":{"start":0,"videoId":""},"message":"0.01 mer","amount":2.38,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5f380c203080e933fe587df3","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-08-15T16:24:00.463Z","updatedAt":"2020-08-15T16:24:35.235Z","token":"EC-6P934493F4731022M","transactionId":"04L1807548587344C"},{"donation":{"user":{"username":"Ami","geo":"FI","email":"[email protected]"},"media":{"start":0,"videoId":""},"message":".","amount":2.37,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5f380ba85fdb306bfe259ff1","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-08-15T16:22:00.389Z","updatedAt":"2020-08-15T16:23:07.153Z","token":"EC-15580574R0466603T","transactionId":"97G82573V6280833C"},{"donation":{"user":{"username":"Christaffa","geo":"SE","email":"[email protected]"},"media":{"start":0,"videoId":""},"message":"Here is a little present for a guy called chriss","amount":10.67,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5e8f74f11b28cc7a262ff0e8","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-04-09T19:18:09.696Z","updatedAt":"2020-04-09T19:18:59.647Z","token":"EC-6V721718BM2027504","transactionId":"73U09025KT621953P"},{"donation":{"user":{"username":"totally the real keppy","geo":"NL","email":"[email protected]"},"media":{"start":0,"videoId":""},"message":"some money to feed your gambling addiction","amount":1,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5e80dc7e593906478b99a4b2","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-03-29T17:35:58.359Z","updatedAt":"2020-03-29T17:36:23.724Z","token":"EC-03X58148UE739170L","transactionId":"8SF26109BV8270519"}],"total":6,"limit":25,"offset":0}

I want it to look closer to this if it is possible: Picture of what I want terminal output to look like

Upvotes: 0

Views: 1455

Answers (2)

user5386938
user5386938

Reputation:

Looks like you have a JSON string. You can use json.loads to get a python dictionary. You can then use json.dumps with indent=4 to get a nicely-indented string representation.

>>> import json
>>> s = '{"first_name": "Justin", "last_name": "Ezequiel", "company_name": "", "address": "5665 McLaughlin ", "city": "Mississauga", "province": "ON", "postal_code": "L5R 3K5", "country": "CA", "phone_number": "", "shipping_cost": "0.00"}'
>>> print(s)
{"first_name": "Justin", "last_name": "Ezequiel", "company_name": "", "address": "5665 McLaughlin ", "city": "Mississauga", "province": "ON", "postal_code": "L5R 3K5", "country": "CA", "phone_number": "", "shipping_cost": "0.00"}
>>> o = json.loads(s)
>>> print(json.dumps(o, indent=4))
{
    "first_name": "Justin",
    "last_name": "Ezequiel",
    "company_name": "",
    "address": "5665 McLaughlin ",
    "city": "Mississauga",
    "province": "ON",
    "postal_code": "L5R 3K5",
    "country": "CA",
    "phone_number": "",
    "shipping_cost": "0.00"
}

Upvotes: 1

patrec
patrec

Reputation: 49

Copy the output of that dictionary and paste it into https://jsonformatter.curiousconcept.com/ and it will give you a nicely formatted JSON object like the one you have in the picture.

Also, remove the first picture, and paste the output in a code-block.

Upvotes: 1

Related Questions