QJsonDocument fails with a confusing error

Anton Yablokov stsav012 at gmail.com
Wed Jun 10 08:35:15 BST 2020


Dear developers,

Consider the following piece of code:

from PyQt5.QtCore import QJsonDocument

json = {
    "catalog": [
        {
            "version": None,
        },
    ]}QJsonDocument(json)

Under Python 3.6+ and PyQt514+ (haven't checked other versions), it results
in the following error at the last line:

TypeError: a value has type 'list' but 'QJsonValue' is expected

QJsonDocument clearly supports lists: QJsonDocument({'a': []}) works fine.

As it turns out, the None value is the reason. Although the docs
<https://doc.qt.io/qt-5/qjsondocument.html#JsonFormat-enum> clearly show
that QJsonDocument supports null values, None is not supported in
PyQt5: QJsonDocument({'a':
None}) results in

TypeError: a value has type 'NoneType' but 'QJsonValue' is expected.

Is it a bug that None is not translated as null? If not, the error message
should be more informative, at least.

Best regards,

Anton
🍏
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200610/b337f381/attachment.htm>


More information about the PyQt mailing list