-1

i want to iterate and check if a new files are updates in the folder then read the files e.g. data.json then access the data and print them . but I cant seem to access the data inside the file it self

error message:with open(json_files) as file: TypeError: expected str, bytes or os.PathLike object, not list

import os, json
import pandas as pd

path_to_json = '/Webservertesting/JsonFiles'
json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')] #creats a lis of the files in folder
print(type(json_files))  # for me this prints ['foo.json']

for jsonfile in json_files:
    print(jsonfile)
    with open(jsonfile,json) as file:
            data = json.load(file)
            print(data)
La Brewers
  • 39
  • 4
  • Does this answer your question? [Python: Read several json files from a folder](https://stackoverflow.com/questions/30539679/python-read-several-json-files-from-a-folder) – Michael Wheeler Oct 10 '21 at 17:01

1 Answers1

1

Try this:

for jsonfile in json_files:
    print(jsonfile)
    with open(os.path.join(path_to_json, jsonfile)) as file:
            data = json.load(file)
            print(data)
Muhammad Hassan
  • 4,079
  • 1
  • 13
  • 27