<div dir="ltr"><p>Dear developers,<br></p><p>Consider the following piece of code:</p>
<pre><code><span>from</span><span> </span><span>PyQt5</span><span>.</span><span>QtCore</span><span> </span><span>import</span><span> </span><span>QJsonDocument</span><span>
json </span><span>=</span><span> </span><span>{</span><span>
</span><span>"catalog"</span><span>:</span><span> </span><span>[</span><span>
</span><span>{</span><span>
</span><span>"version"</span><span>:</span><span> </span><span>None</span><span>,</span><span>
</span><span>},</span><span>
</span><span>]</span><span>
</span><span>}</span><span>
</span><span>QJsonDocument</span><span>(</span><span>json</span><span>)</span></code></pre>
<p>Under Python 3.6+ and PyQt514+ (haven't checked other versions), it results in the following error at the last line:</p>
<p><code>TypeError: a value has type 'list' but 'QJsonValue' is expected</code></p>
<p><code>QJsonDocument</code> clearly supports lists: <code>QJsonDocument({'a': []})</code> works fine.</p><p>As it turns out, the <code>None</code> value is the reason. Although the <a href="https://doc.qt.io/qt-5/qjsondocument.html#JsonFormat-enum" rel="nofollow noreferrer" target="_blank">docs</a> clearly show that <code>QJsonDocument</code> supports <code>null</code> values, <code>None</code> is not supported in PyQt5: <code>QJsonDocument({'a': None})</code> results in</p>
<p><code>TypeError: a value has type 'NoneType' but 'QJsonValue' is expected</code>.</p><p>Is it a bug that <span style="font-family:monospace">None</span> is not translated as <span style="font-family:monospace">null</span>? If not, the error message should be more informative, at least.<br></p><p>Best regards,</p><p>Anton</p><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font size="6">🍏</font><br></div></div></div></div></div></div></div></div>