Skip to content

Commit

Permalink
added str_to_obj method
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Oct 15, 2024
1 parent e3e5dae commit fa081c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions osbot_utils/utils/Json.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
import os

from osbot_utils.utils.Misc import str_lines, str_md5, str_sha256
from osbot_utils.utils.Misc import str_lines, str_md5, str_sha256
from osbot_utils.utils.Files import file_create_gz, file_create, load_file_gz, file_contents, file_lines, file_lines_gz
from osbot_utils.utils.Zip import str_to_gz, gz_to_str
from osbot_utils.utils.Zip import str_to_gz, gz_to_str


def json_dumps(python_object, indent=4, pretty=True, sort_keys=False, default=str, raise_exception=False):
Expand Down
6 changes: 6 additions & 0 deletions osbot_utils/utils/Objects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# todo add tests
import inspect
import json
import pickle
import sys
import types
Expand Down Expand Up @@ -151,6 +152,9 @@ def obj_to_dict(target):
return {obj_to_dict(item) for item in target}
return target # Return non-object types as is

def str_to_obj(target):
return dict_to_obj(json.loads(target))

def enum_from_value(enum_type, value):
try:
return enum_type[value] # Attempt to convert the value to an Enum member by name
Expand Down Expand Up @@ -390,6 +394,8 @@ def value_type_matches_obj_annotation_for_attr(target, attr_name, value):
base_types = base_classes
bytes_to_obj = pickle_load_from_bytes

json_to_obj = str_to_obj

full_type_name = class_full_name

obj_list_set = obj_keys
Expand Down

0 comments on commit fa081c9

Please sign in to comment.