compare string with json in python without case sensitive

The method str. casefold is the method that you want to use when you need to do caseless, or case-insensitive, comparisons in Python. This method is similar to the method str

def storetext(text):
    try:        
        new_data = {"text":text }
        
        with open("data.json",'r+') as file:
            file_data = json.load(file)
            if text.casefold() not in file_data["details"].__str__():
                file_data["details"].append(new_data)
                file.seek(0)
                json.dump(file_data, file, indent = 4)

        return {"message": "User data submitted successfully!","arraytojson":""}
    except HTTPException as e:
        raise e
    except Exception as e:
        raise HTTPException(
            status_code=500, detail=f"An error occurred: {str(e)}")
    

Discover more from Soa Technology | Aditya Website Development Designing Company

Subscribe to get the latest posts sent to your email.



Leave a Reply

Discover more from Soa Technology | Aditya Website Development Designing Company

Subscribe now to keep reading and get access to the full archive.

Continue reading