0

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?

StSav012
  • 776
  • 5
  • 15

1 Answers1

0

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.

StSav012
  • 776
  • 5
  • 15