Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting mongoengine objects to JSON #1

Closed
doismellburning opened this issue Apr 4, 2012 · 4 comments
Closed

Converting mongoengine objects to JSON #1

doismellburning opened this issue Apr 4, 2012 · 4 comments
Milestone

Comments

@doismellburning
Copy link

It's entirely possible that I'm missing something, but it seems like the de facto way of converting mongoengine objects (my primary use-case is Document) to JSON is the following code:

https://groups.google.com/forum/#!activity/mongoengine-users/N7p0Mi065swJ/mongoengine-users/ya9XbrAVwi4/N7p0Mi065swJ

Am I missing a nicer way, and if not, would a pull request with an in-mongoengine-method be appreciated?

rozza added a commit that referenced this issue Nov 8, 2012
- Added to_json and from_json to Document (#1)
- Added to_json and from_json to QuerySet (#131)
@rozza
Copy link
Contributor

rozza commented Nov 8, 2012

Added Document level support eg:

my_doc.to_json()
MyDoc.from_json(json_data)

And Queryset support eg:

MyDoc.objects(open=True).to_json()
MyDoc.objects.from_json(json_data)

** Note - from_json does not try to persist data - so call has to be saved on each Document instance.

@rozza rozza closed this as completed Nov 8, 2012
@lig
Copy link
Contributor

lig commented Nov 19, 2012

@rozza it will be helpful to be able to provide default parameter to json.dump call in to_json method really.

@molavy
Copy link

molavy commented Jul 25, 2013

to_json has problem with unicode strings
how can i use ensure_ascii=False with to_json

@fthzkrtn
Copy link

I tried too many ways to cast the document inherited object to json but it was hard to do that till find this thread! Thanks.

MRigal pushed a commit that referenced this issue Jun 26, 2015
lafrech pushed a commit that referenced this issue Jun 24, 2016
* fixed the bug where dynamic doc has indx inside dict field
lafrech pushed a commit that referenced this issue Sep 7, 2016
pull new changes from original
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants