i
is only the filename. you should give the full path to the program.
example: let first file be stackoverflow.json
you try to open with filename such as:
open('stackoverflow.json', 'r')
what you should do is:
open('C:/Users/new/stackoverflow.json', 'r')
so the code should do it:
files = []
base_path = 'C:/Users/new'
for i in os.listdir(base_path):
if i.endswith('.json'):
full_path = '%s/%s' % (base_path, i)
files.append(open(full_path, 'r', encoding='utf-8').read())
print("starting to print json documents...")
for single_file in files:
print(single_file)
print("printing done")
EDIT: as @khelwood states, you should also replace read
with read()
.