https://github.com/datenhahn/python-sassyjson
sassyjson is an automatic json objectmapper for python.
https://github.com/datenhahn/python-sassyjson
Last synced: about 1 month ago
JSON representation
sassyjson is an automatic json objectmapper for python.
- Host: GitHub
- URL: https://github.com/datenhahn/python-sassyjson
- Owner: datenhahn
- License: apache-2.0
- Created: 2022-06-17T21:42:03.000Z (about 4 years ago)
- Default Branch: develop
- Last Pushed: 2022-06-20T12:55:23.000Z (about 4 years ago)
- Last Synced: 2025-02-23T22:28:13.417Z (over 1 year ago)
- Language: Python
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sassyjson
sassyjson is an automatic json objectmapper for python.
## Install
```
pip install
```
## Usage
```python
@dataclass
class MyNestedClass:
message: str
@dataclass
class MyCustomClass:
timestamp: datetime
nested_message: MyNestedClass
my_instance = MyCustomClass(timestamp=datetime(2022,6,17),
nested_message=MyNestedClass("Hello World!"))
# Will generate the following string from the instance:
# '{"nested_message": {"message": "Hello World!"}, "timestamp": "2022-06-17T00:00:00.000000"}'
json_string = sassyjson.to_json(my_instance)
# Will generate a new MyCustomClass instance from the json string
new_instance = sassyjson.from_json(json_string, MyCustomClass)
```