Skip to content

Commit

Permalink
Fixed conversion of lists to JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelamud committed Nov 2, 2023
1 parent d93b9f7 commit d26f59c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "moeralib"
version = "0.14.3"
version = "0.14.4"
authors = [
{name = "Shmuel Leib Melamud", email = "[email protected]"},
]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = moeralib
version = 0.14.3
version = 0.14.4

[options]
install_requires =
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='moeralib',
version='0.14.3',
version='0.14.4',
install_requires=[
'requests>=2.31.0',
'camel-converter',
Expand Down
14 changes: 14 additions & 0 deletions src/moeralib/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,27 @@ def from_json(cls, data) -> Structure | None:
instance.__dict__.update(data)
return instance

@staticmethod
def list_to_json(a_list):
out = []
for item in a_list:
if isinstance(item, Structure):
out.append(item.json())
elif isinstance(item, list):
out.append(Structure.list_to_json(item))
else:
out.append(item)
return out

def json(self):
json = {}
for name, value in self.__dict__.items():
if name.startswith('_'):
continue
if isinstance(value, Structure):
value = value.json()
elif isinstance(value, list):
value = Structure.list_to_json(value)
json[to_camel(name)] = value
return json

Expand Down

0 comments on commit d26f59c

Please sign in to comment.