mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2026-01-08 16:34:19 +01:00
Add new module bfxapi._utils.json_decoder.
This commit is contained in:
13
bfxapi/_utils/json_decoder.py
Normal file
13
bfxapi/_utils/json_decoder.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from typing import Dict, Any
|
||||
|
||||
import re, json
|
||||
|
||||
def _to_snake_case(string: str) -> str:
|
||||
return re.sub(r"(?<!^)(?=[A-Z])", "_", string).lower()
|
||||
|
||||
def _object_hook(data: Dict[str, Any]) -> Any:
|
||||
return { _to_snake_case(key): value for key, value in data.items() }
|
||||
|
||||
class JSONDecoder(json.JSONDecoder):
|
||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||
super().__init__(object_hook=_object_hook, *args, **kwargs)
|
||||
@@ -1,11 +1,11 @@
|
||||
import json
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from typing import \
|
||||
Union, List, Dict, \
|
||||
Any
|
||||
|
||||
import json
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
_ExtJSON = Union[Dict[str, "_ExtJSON"], List["_ExtJSON"], \
|
||||
bool, int, float, str, Decimal, None]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user