Mar-16-2020, 12:41 AM
Is it possible in python 3.8 to print list in one line rather than printing each item on new line via json.dumps? Are there any other json libraries that can do it?
json.dumps list output
|
||||
Mar-16-2020, 12:41 AM
Is it possible in python 3.8 to print list in one line rather than printing each item on new line via json.dumps? Are there any other json libraries that can do it?
json dumps converts to a dictionary.
this dictionary can be better viewed as a formatted text file. python has a tool that you can use to convert and format JSON data to a nicely formatted text file. from command line, Linux format is: cat myfile.json | python -m json.tool > myfile.txt
Mar-16-2020, 07:32 AM
(Mar-16-2020, 02:23 AM)Larz60+ Wrote: But this is for command line. I need something that will print inner lists of my dict in one line. Like here https://stackoverflow.com/questions/2626...n/54356188 The answers are pretty old there, so maybe there is a new solution?
Mar-16-2020, 07:52 AM
Out of interest, why?
Mar-16-2020, 09:13 AM
Mar-16-2020, 09:49 AM
Ha, nice little printing exercise (one can print into file as well).
Using data from SO example:
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Mar-16-2020, 10:11 AM
here's my dictionary display:
Mar-16-2020, 05:07 PM
It seems that there's no an easy way to achieve one line printing in .json. Thanks for the answers!
Mar-16-2020, 08:58 PM
Have you looked at the documentation? https://docs.python.org/3/library/json.html
Mar-16-2020, 09:10 PM
Yes, but I haven't found a way to control inner lists output without writing my own encoder
| ||||
|