QJsonDocument fails with a confusing error

135 Views Asked by At

Consider the following piece of code:

from PyQt5.QtCore import QJsonDocument

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

Under Python 3.7 and PyQt 5.14.2, it results in the following error at the last line:

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

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

So, what's going on?

1

There are 1 best solutions below

0
On

As it turns out, the None value is the reason. Although the docs 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.


The developers explained that that was an omission. They have resolved the issue.