Skip to content

Commit

Permalink
remove encoding option from json field... (#584)
Browse files Browse the repository at this point in the history
prepare for python 3.9 support
  • Loading branch information
abom authored Apr 26, 2021
1 parent 9c51f70 commit ab86c5a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions jumpscale/core/base/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,18 +1041,16 @@ def to_raw(self, value):


class Json(String):
def __init__(self, default="{}", encoding="utf-8", **kwargs):
def __init__(self, default="{}", **kwargs):
"""
Json field, will check if the value is a valid json string.
It will hold json strings, if the value is not string, it will be converted.
Args:
default (str, optional): default value. Defaults to "{}"
encoding: encoding to be used when serializing the value. Defaults to "utf-8"
kwargs: other keyword arguments supported by `String`
"""
self.encoding = encoding
super().__init__(default=default, **kwargs)

def validate(self, value):
Expand All @@ -1072,7 +1070,7 @@ def validate(self, value):

# if it's a string, try to load it
try:
json.loads(value, encoding=self.encoding)
json.loads(value)
except Exception as e:
raise ValidationError(f"'{value}' isn't a valid json, {e}") from e

Expand Down

0 comments on commit ab86c5a

Please sign in to comment.