Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Robert Abram
Copyright (c) 2022-2026 Robert Abram

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ Data from a JSON String

{"test_key": "test_value"}

data = dict(obj)
print(data)

{"test_key": "test_value"}

Data from a python dictionary

::
Expand Down
49 changes: 47 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
line-length = 120
target-version = ['py37', 'py38', 'py39', 'py310', 'py311', 'py312', 'py313', 'py314']
[build-system]
requires = ["setuptools >= 77.0.3"]
build-backend = "setuptools.build_meta"

[project]
name="python-easy-json"
version="1.2.4"
python_requires=">=3.7"
license="MIT"
description="A simple, yet powerful, JSON/python dictionary to object deserialization"
authors = [
{ name = "Robert Abram", email = "rabram991@gmail.com" },
]
dependencies = [ "dateutils", ]
requires-python = ">= 3.9"
readme="README.rst"
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
]
keywords=[
"serialization",
"rest",
"json",
"api",
"marshal",
"marshalling",
"deserialization",
"schema",
"model",
"models",
"data"
]

[project.urls]
Homepage = "https://github.com/robabram/python-easy-json"
Repository = "https://github.com/robabram/python-easy-json"
Changelog = "https://github.com/robabram/python-easy-json"
Issues = "https://github.com/robabram/python-easy-json/issues"
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

70 changes: 0 additions & 70 deletions setup.py

This file was deleted.

7 changes: 7 additions & 0 deletions src/python_easy_json/json_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,10 @@ def update(self, *args, **kwargs) -> "JSONObject":
setattr(self, k, v)

return self

def __iter__(self):
""" Allow casting to Dict, IE: dict({JSONObject instance}) """
data = self.to_dict(dates_to_str=True)
if data:
for k, v in data.items():
yield k, v
9 changes: 9 additions & 0 deletions tests/test_simple_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,12 @@ def test_add_invalid_operand(self):
pass

self.assertFalse(hasattr(obj, 'other_prop'))

def test_cast_to_dict(self):
""" Test cast a JSONObject to a dict """
obj = JSONObject({'test_prop': 123})
self.assertIsInstance(obj, JSONObject)

dict1 = dict(obj)
dict2 = obj.to_dict(dates_to_str=True)
self.assertEqual(dict1, dict2)