File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 33import datetime
44import hashlib
55import io
6+ import json
67import mimetypes
78import multiprocessing
89import re
@@ -1004,11 +1005,18 @@ def any_bytes_to_text_pages_or_df(
10041005 except UnsupportedDocumentError :
10051006 pass
10061007
1007- if mime_type == "text/plain" :
1008- text = f_bytes .decode ()
1009- else :
1010- ext = mimetypes .guess_extension (mime_type ) or ""
1011- text = pandoc_to_text (f_name + ext , f_bytes )
1008+ match mime_type :
1009+ case "text/plain" | "text/markdown" :
1010+ text = f_bytes .decode ()
1011+ case "application/json" :
1012+ try :
1013+ text = json .dumps (json .loads (f_bytes .decode ()), indent = 2 )
1014+ except json .JSONDecodeError as e :
1015+ raise UserError (f"Invalid JSON file: { e } " ) from e
1016+ case _:
1017+ ext = mimetypes .guess_extension (mime_type ) or ""
1018+ text = pandoc_to_text (f_name + ext , f_bytes )
1019+
10121020 return [text ]
10131021
10141022
You can’t perform that action at this time.
0 commit comments