Answer the question
In order to leave comments, you need to log in
How to convert JSON to readable form using Python?
Please help solve the problem:
The task is to write a script that takes the path to a file with arbitrary data in JSON format as input and outputs its contents to the console in a readable form: adds line breaks, left indents and spaces.
My code is not processing everything. Just a hint, thanks!
import json
stt = 'js.txt'
def load_data(filepath):
with open(filepath,'r') as myfile:
return json.load(myfile)
def pretty_print_json(data):
for st in data:
print(json.dumps(st, indent=" ",ensure_ascii=False, sort_keys=True))
pretty_print_json(load_data(stt))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question