class Person:
first_name = superjson.Property()
last_name = superjson.Property()
posts = superjson.Collection(Post)
class Post:
title = superjson.Property()
description = superjson.Property()
# ^^^ this approach is very similar to Django models/forms
Then, given JSON like this:
{
"first_name": "John",
"last_name": "Smith",
"posts": [
{"title": "title #1", "description": "description #1"},
{"title": "title #2", "description": "description #2"},
{"title": "title #3", "description": "description #3"}
]
}
I want it to build a proper Person object with everything inside it set:
p = superjson.deserialize(json, Person) # note, root type is explicitly provided
print p.first_name # 'John'
print p.last_name # 'Smith'
print p.posts[0].title # 'title #1'
# etc...
- Sure it should also facilitate serialization
- It should either serialize/deserialize time to/from ISO-8601 by default or be easy to achieve this in couple lines of code.
So, I’m looking for this superjson. Did anyone see anything similar?
Colander, combined with limone does exactly this.
You define a schema using
colander:then pass in your JSON data structure: