Skip to content

Commit d439938

Browse files
committed
feat: migrate JSON handling to orjson
Replace stdlib json with orjson for faster serialization/deserialization in file_to_json. Produces 2-space indented output via OPT_INDENT_2.
1 parent 968bfbf commit d439938

File tree

3 files changed

+199
-4
lines changed

3 files changed

+199
-4
lines changed

browsr/widgets/windows.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
from __future__ import annotations
66

7-
import json
87
from json import JSONDecodeError
98
from typing import Any, ClassVar
109

10+
import orjson
1111
import pandas as pd
1212
from art import text2art
1313
from numpy import nan
@@ -79,8 +79,10 @@ def file_to_json(self, file_path: UPath, max_lines: int | None = None) -> str:
7979
"""
8080
code_str = self.file_to_string(file_path=file_path)
8181
try:
82-
code_obj = json.loads(code_str)
83-
code_str = json.dumps(code_obj, indent=2)
82+
code_obj = orjson.loads(code_str)
83+
code_str = orjson.dumps(code_obj, option=orjson.OPT_INDENT_2).decode(
84+
"utf-8"
85+
)
8486
except JSONDecodeError:
8587
pass
8688
if max_lines:

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ dependencies = [
3030
"universal-pathlib~=0.2.6",
3131
"Pillow>=11.3.0",
3232
"PyMuPDF~=1.26.3",
33-
"pyperclip~=1.9.0"
33+
"pyperclip~=1.9.0",
34+
"orjson~=3.11.5"
3435
]
3536
description = "TUI File Browser App"
3637
keywords = []

0 commit comments

Comments
 (0)