-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
JSON module does not throw exception when object is not serialisable #1719
Comments
This was a design decision. It's undefined behaviour if you serialise
something that can't be serialised.
I guess the bigger issue is: do we need to provide a mechanism to serialise
a larger set of types?
|
pickle works on everything I've tried so far, and it is the classic Python solution. The version in the MicroPython library is very micro, and doubtless less efficient than cPython's C coded version but it does work. It seems a lot to ask of someone new to Python or JSON to know what datatypes are valid. |
+1. It's also should be pointed out that MicroPython provides "ujson" module, which can't be compared one-to-one to CPython. Users may write actual "json" module which would work as they desire. |
I lately had a case when I wanted extensibility. But turned out, I want extensibility which even CPython doesn't provide: I wanted to get instances of particular namedtuple type for a JSON arrays. So, I skipped following that further. |
restrict 'make translate' to include only those directories we have ports for
Serializing a bytes object still does not seem to raise and exception - just silently create invalid JSON.
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\t\n\u000b\u000c\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !"#$%&'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������" |
This came up in http://forum.micropython.org/viewtopic.php?f=6&t=953&p=7551#p7551
cPython throws an exception on an attempt to serialise a bytes object (regardless of object contents):
MicroPython does not throw an exception but does not work: the restored object is of type str and its contents differs from that saved:
The text was updated successfully, but these errors were encountered: