mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 11:39:18 +00:00
community: fixes json loader not getting texts with json standard (#27327)
This PR fixes JSONLoader._get_text not converting objects to json string correctly. If an object is serializable and is not a dict, JSONLoader will use python built-in str() method to convert it to string. This may cause object converted to strings not following json standard. For example, a list will be converted to string with single quotes, and if json.loads try to load this string, it will cause error. --------- Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
@@ -188,7 +188,7 @@ class JSONLoader(BaseLoader):
|
||||
# In case the text is None, set it to an empty string
|
||||
elif isinstance(content, str):
|
||||
return content
|
||||
elif isinstance(content, dict):
|
||||
elif isinstance(content, (dict, list)):
|
||||
return json.dumps(content) if content else ""
|
||||
else:
|
||||
return str(content) if content is not None else ""
|
||||
|
Reference in New Issue
Block a user