Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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?

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

```