diff --git a/libs/community/langchain_community/document_loaders/json_loader.py b/libs/community/langchain_community/document_loaders/json_loader.py index 839fe482f62de4..c99e8c6d2720ca 100644 --- a/libs/community/langchain_community/document_loaders/json_loader.py +++ b/libs/community/langchain_community/document_loaders/json_loader.py @@ -185,12 +185,11 @@ def _get_text(self, sample: Any) -> str: ) # In case the text is None, set it to an empty string - elif isinstance(content, str): - return content - elif isinstance(content, dict): - return json.dumps(content) if content else "" else: - return str(content) if content is not None else "" + try: + return json.dumps(content) if content else "" + except TypeError: + return str(content) if content is not None else "" def _get_metadata( self, sample: Dict[str, Any], **additional_fields: Any