Skip to content

Commit a413d59

Browse files
committed
Convert the value to JSON string for consistent return type
1 parent 9301fa3 commit a413d59

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/tools/json.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from typing import Union, Mapping, List, TYPE_CHECKING, Any
23
from redis.exceptions import RedisError
34

@@ -57,11 +58,11 @@ async def json_get(name: str, path: str = "$") -> str:
5758
try:
5859
r = RedisConnectionManager.get_connection()
5960
value = r.json().get(name, path)
60-
return (
61-
value
62-
if value is not None
63-
else f"No data found at path '{path}' in '{name}'."
64-
)
61+
if value is not None:
62+
# Convert the value to JSON string for consistent return type
63+
return json.dumps(value, ensure_ascii=False, indent=2)
64+
else:
65+
return f"No data found at path '{path}' in '{name}'."
6566
except RedisError as e:
6667
return f"Error retrieving JSON value at path '{path}' in '{name}': {str(e)}"
6768

0 commit comments

Comments
 (0)