Tagged Questions
-2
votes
3answers
48 views
Take off '[' from Json string?
I have a JSON return string from MongoDB
[{'api_calls_per_day': 0.29411764705882354, '_id': ObjectId('51948e5bc25f4b1d1c0d303a'), 'api_calls_total': 5, 'api_calls_with_key': 3, ...
1
vote
2answers
58 views
TypeError: ObjectId('') is not JSON serializable
My response back from MongoDB after querying an aggregated function on document using Python, It returns valid response and i can print it but can not return it.
Error:
TypeError: ...
1
vote
3answers
44 views
How to truncate data in a dict so that the resulting JSON isn't longer than n bytes?
I have a python 2.7 dict such as {u"eat": u"糖果", u"drink": u"café"}, and I need to transfer it using JSON. The JSON string must be regular ASCII and it must be less than 256 chars.
So far, I have ...
0
votes
1answer
43 views
Python: json erasing vocabulary file data instead of writing
Hello and thanks for coming.
I have a problem, writing JSON dict filled with data from the GUI: after execution of this script, i got an empty .json file, even if it was filled with something. ...
1
vote
1answer
214 views
Flask mongoengine for a json api
I want to develop a json api using flask-mongoengine, but it seems a litle difficult to return json responses.
This is my view's code:
@users.route('/', methods=["GET"])
def index():
return ...
1
vote
2answers
73 views
Custom JSONEncoder returns malformed Strings
I'm implementing my own JSONEncoder for handling different classes exactly as I need them. Unfortunately, my custom encoder returns somewhat malformed strings. They are surrounded by quotes and ...
4
votes
1answer
309 views
Why doesn't this custom json encoder work?
While trying out an answer that initially suggested using a custom JSONEncoder subclass to solve a printing problem, I discovered that what the documentation suggests doing in the Extending ...
1
vote
1answer
459 views
Get Python JSON to serialize datetime
Have some nested objects that I'd like serialize using JSON. The problem is that some of the properties contain datetimes. When I try to serialize these pbjects, Python throws an exception:
...
1
vote
1answer
633 views
Python: Json encode a nested data structure with namedtuples, dates
I have a nested Python data structure with datetime.datetime objects and namedtuples along the following lines:
from datetime import datetime as dt
from datetime import timedelta
from collections ...
4
votes
1answer
7k views
JSON load/dump in Python
From the docs:
http://docs.python.org/library/json.html
>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')
[u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
I modified it like this:
...
-2
votes
1answer
397 views
I need help understanding some pythonic “dictify” / “jsonify” code fragments
I need help understanding this python jsonify/dictify code so I can replicate it:
TYPES = {}
# auto-register all already defined subclasses of CustomObject to the types map
# so they will become ...
3
votes
2answers
561 views
Serializing Python bytestrings to JSON, preserving ordinal character values
I have some binary data produced as base-256 bytestrings in Python (2.x). I need to read these into JavaScript, preserving the ordinal value of each byte (char) in the string. If you'll allow me to ...