Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evuez/ojm
:snake: Object JSON Mapping?
https://github.com/evuez/ojm
Last synced: about 1 month ago
JSON representation
:snake: Object JSON Mapping?
- Host: GitHub
- URL: https://github.com/evuez/ojm
- Owner: evuez
- License: mit
- Created: 2015-10-17T12:15:28.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-17T12:16:49.000Z (about 9 years ago)
- Last Synced: 2024-10-09T09:51:34.811Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 137 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OJM: Object JSON Mapping?
Allows you to save Python objects to JSON files.
It's an old piece of code, it seems to kinda work, but the code isn't what you'd call "pretty".
# Demo
See `demo.py` for full classes definition.
```python
import ojm# Define classes...
class Human(ojm.Model):
pass
# ...class Organ(ojm.Model):
pass
# ...# Register models
ojm.register(Human)
ojm.register(Organ)# Have fun!
john = Human('John Doe', 42)
john.add_organ(Organ('heart'))
john.save()# `duplicate()` is required to later save this new instance
jane = Human.load(john.uuid).duplicate()
jane.name = 'Jane Doe'
print(jane.embedded_organs[0].name) # heart
jane.save()jane.linked_human = john
jane.update()print(Human.load(jane.uuid).linked_human.name) # John Doe
```