Unexpected 500 error when Json file uploaded to file api

Using the following Code to upload files to Gemini api

   def single_completion(self, user_prompt, files: list[str], file_name: str = None) -> str:

        # Load the files
        my_files = []
        for file in files:
            my_file = genai.upload_file(file)
            # wait for processing to complete.
            while my_file.state.name == "PROCESSING":
                time.sleep(5)
                my_file = genai.get_file(name=my_file.name)
            my_files.append(my_file)
        print(my_files)
        # send the request to the AI
        response = self.model.generate_content([user_prompt, *my_files])
        if file_name is not None:
            try:
                # Parse the json returned and save it
                json_data = json.loads(response.text)
                write_json_file(json_data, file_name)
            except json.JSONDecodeError as e:
                write_json_file(response.text, file_name)
                # log error of bad json.
                print("Error: Invalid JSON data:", e)

        return response.text

This is my standard code which i have been using for everything previously.

Currently i am trying to upload a large JSon file. The file uploads just fine but when i try to make a request from the API to describe the data I get an error.

Yet if i read the text of the file and upload it as the prompt instead of using the file api it works fine.

Is there an issue with the parsing of json files that have been uploaded? This is data back from an api endpoint so i cant really give it to you to test with. I can say that its standard json format. However some of the values do contain HTML.

Example

    "key": "html",
    "value": "<!-- html javascript stuff here. -->"

Linda

Hi @LindaLawton , currently gemini api does not support json file for processing. Please follow the link below for supported MIME types

Linda, there are many json-to-xml converters available. One popular option is Jackson.

It would also make sense for Google to do the conversion transparently, and thus extend the document mime types to additionally handle json.