Skip to content

RAG not able to read .json files #9049

Discussion options

You must be logged in to vote

Taking inspiration from this reply (which is basically the answer), I rewrote the code for extracting documents in this way:

directory_path = "/content/Data/"
documents = SimpleDirectoryReader(directory_path).load_data()

json_docs = []
for filename in os.listdir(directory_path):
    filepath = os.path.join(directory_path, filename)
    
    # Check if the file is a JSON file
    if filename.endswith(".json") and os.path.isfile(filepath):
        # Load data using JSONReader for JSON files
        json_data = JSONReader().load_data(filepath)
        json_docs.extend(json_data)

merged_docs = documents + json_docs

So basically the first line of the code in the question is now substitued w…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@LorenzoCutrupi
Comment options

Answer selected by LorenzoCutrupi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant