django dynamic serializers

41 views
Skip to first unread message

Shekar Tippur

unread,
Jul 9, 2015, 4:20:40 PM7/9/15
to django...@googlegroups.com
Hello,

I have a source of data that can have a dynamic json structure.
Is there a way to dynamically create models based on this?

- Shekar

James Schneider

unread,
Jul 9, 2015, 4:41:37 PM7/9/15
to django...@googlegroups.com
When you mention dynamic, do you mean that the data has a known set of
possible fields, but may only populate a subset of them? Or will it
just have random fields that you may not know about ahead of time? If
you have a way to articulate all of the possible fields that the data
source may use, then I would suggest creating a large model (or set of
models if needed) to encompass all of the possible data fields with
reasonable defaults. You'll also need to building the appropriate
de-serialization code to drop the various bits of data into those
models.

You can probably write some code to grab the fields and create a
skeleton of a model definition (if the definition will remain static
once built), although it may be difficult to determine whether or not
a particular field should be a Char or an Integer field, etc.

If you are using Postgres as your database backend, you also have the
option of storing the JSON directly into an HStore field. See
https://docs.djangoproject.com/en/dev/ref/contrib/postgres/fields/#hstorefield
for more information.

Django doesn't support the idea of dynamic models since models are
tied directly to the database schema, and I doubt you want to modify
your database schema dynamically based on incoming data.

-James
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/49075845-52fe-4e9f-8e66-292491baea0a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Shekar Tippur

unread,
Jul 9, 2015, 5:43:32 PM7/9/15
to django...@googlegroups.com
James,

Thanks for the response.
The data is latter. I dont know the structure of incoming message. It can be a simple json or a nested json.
I dont have a persistance store. I have a pipeline where a random json comes in and I would like to model the pipeline based on its structure. I need to read this json, present it to the user for further processing.
I was wondering if there is something equivalent to jackson library in Java. 

- Shekar
Reply all
Reply to author
Forward
0 new messages