Skip to content

PythonQt.QtCore.QJsonValue · declarations 001

Back to PythonQt.QtCore.QJsonValue

Array instance-attribute

Array: Any

Bool instance-attribute

Bool: Any

Double instance-attribute

Double: Any

Null instance-attribute

Null: Any

Object instance-attribute

Object: Any

String instance-attribute

String: Any

Undefined instance-attribute

Undefined: Any

fromVariant

fromVariant(variant: Any) -> Any

X.fromVariant(variant) -> PythonQt.QtCore.QJsonValue

Supplemental documentation: Qt 5 reference:

[static] QJsonValue QJsonValue::fromVariant(const QVariant \&variant)

Converts variant to a QJsonValue and returns it.

The conversion will convert QVariant types as follows:

Source type Destination type
- QMetaType::Nullptr QJsonValue::Null
- QMetaType::Bool QJsonValue::Bool
- QMetaType::Int - QMetaType::UInt - QMetaType::LongLong - QMetaType::ULongLong - QMetaType::Float - QMetaType::Double QJsonValue::Double
- QMetaType::QString QJsonValue::String
- QMetaType::QStringList - QMetaType::QVariantList QJsonValue::Array
- QMetaType::QVariantMap - QMetaType::QVariantHash QJsonValue::Object
- QMetaType::QUrl QJsonValue::String. The conversion will use QUrl::toString() with flag QUrl::FullyEncoded, so as to ensure maximum compatibility in parsing the URL
- QMetaType::QUuid QJsonValue::String. Since Qt 5.11, the resulting string will not include braces
- QMetaType::QCborValue Whichever type QCborValue::toJsonValue() returns.
- QMetaType::QCborArray QJsonValue::Array. See QCborValue::toJsonValue() for conversion restrictions.
- QMetaType::QCborMap QJsonValue::Map. See QCborValue::toJsonValue() for conversion restrictions and the "stringification" of map keys.

Loss of information and other types

QVariant can carry more information than is representable in JSON. If the QVariant is not one of the types above, the conversion is not guaranteed and is subject to change in future versions of Qt, as the UUID one did. Code should strive not to use any other types than those listed above.

If QVariant::isNull() returns true, a null QJsonValue is returned or inserted into the list or object, regardless of the type carried by QVariant. Note the behavior change in Qt 6.0 affecting QVariant::isNull() also affects this function.

A floating point value that is either an infinity or NaN will be converted to a null JSON value. The values outside the range of ±2^53 may lose precision, because they are converted to a double QJsonValue.

For other types not listed above, a conversion to string will be attempted, usually but not always by calling QVariant::toString(). If the conversion fails the value is replaced by a null JSON value. Note that QVariant::toString() is also lossy for the majority of types. For example, if the passed QVariant is representing raw byte array data, it is recommended to pre-encode it to Base64 (or another lossless encoding), otherwise a lossy conversion using QString::fromUtf8() will be used.

Please note that the conversions via QVariant::toString() are subject to change at any time. Both QVariant and QJsonValue may be extended in the future to support more types, which will result in a change in how this function performs conversions.

See also toVariant() and QCborValue::fromVariant().

Upstream PySide2 reference signatures (binding differences may apply):

fromVariant(variant: typing.Any) -> PySide2.QtCore.QJsonValue

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#fromVariant

isArray

isArray() -> bool

X.isArray() -> bool

Supplemental documentation: Qt 5 reference:

bool QJsonValue::isArray() const

Returns true if the value contains an array.

See also toArray().

Upstream PySide2 reference signatures (binding differences may apply):

isArray(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#isArray

isBool

isBool() -> bool

X.isBool() -> bool

Supplemental documentation: Qt 5 reference:

bool QJsonValue::isBool() const

Returns true if the value contains a boolean.

See also toBool().

Upstream PySide2 reference signatures (binding differences may apply):

isBool(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#isBool

isDouble

isDouble() -> bool

X.isDouble() -> bool

Supplemental documentation: Qt 5 reference:

bool QJsonValue::isDouble() const

Returns true if the value contains a double.

See also toDouble().

Upstream PySide2 reference signatures (binding differences may apply):

isDouble(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#isDouble

isNull

isNull() -> bool

X.isNull() -> bool

Supplemental documentation: Qt 5 reference:

bool QJsonValue::isNull() const

Returns true if the value is null.

Upstream PySide2 reference signatures (binding differences may apply):

isNull(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#isNull

isObject

isObject() -> bool

X.isObject() -> bool

Supplemental documentation: Qt 5 reference:

bool QJsonValue::isObject() const

Returns true if the value contains an object.

See also toObject().

Upstream PySide2 reference signatures (binding differences may apply):

isObject(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#isObject

isString

isString() -> bool

X.isString() -> bool

Supplemental documentation: Qt 5 reference:

bool QJsonValue::isString() const

Returns true if the value contains a string.

See also toString().

Upstream PySide2 reference signatures (binding differences may apply):

isString(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#isString

isUndefined

isUndefined() -> bool

X.isUndefined() -> bool

Supplemental documentation: Qt 5 reference:

bool QJsonValue::isUndefined() const

Returns true if the value is undefined. This can happen in certain error cases as e.g. accessing a non existing key in a QJsonObject.

Upstream PySide2 reference signatures (binding differences may apply):

isUndefined(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#isUndefined

operator_assign

operator_assign(other: Any) -> Any

X.operator_assign(other) -> PythonQt.QtCore.QJsonValue

toArray

toArray(defaultValue: Any) -> Any

X.toArray(defaultValue) -> PythonQt.QtCore.QJsonArray

Supplemental documentation: Qt 5 reference:

QJsonArray QJsonValue::toArray(const QJsonArray \&defaultValue) const

Converts the value to an array and returns it.

If type() is not Array, the defaultValue will be returned.

QJsonArray QJsonValue::toArray() const

This is an overloaded function.

Converts the value to an array and returns it.

If type() is not Array, a QJsonArray() will be returned.

Upstream PySide2 reference signatures (binding differences may apply):

toArray(self) -> PySide2.QtCore.QJsonArray
toArray(self, defaultValue: PySide2.QtCore.QJsonArray) -> PySide2.QtCore.QJsonArray

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#toArray

toBool

toBool(defaultValue: bool) -> bool

X.toBool(defaultValue) -> bool

Supplemental documentation: Qt 5 reference:

bool QJsonValue::toBool(bool defaultValue \= false) const

Converts the value to a bool and returns it.

If type() is not bool, the defaultValue will be returned.

Upstream PySide2 reference signatures (binding differences may apply):

toBool(self, defaultValue: bool=...) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#toBool

toDouble

toDouble(defaultValue: float) -> float

X.toDouble(defaultValue) -> float

Supplemental documentation: Qt 5 reference:

double QJsonValue::toDouble(double defaultValue \= 0) const

Converts the value to a double and returns it.

If type() is not Double, the defaultValue will be returned.

Upstream PySide2 reference signatures (binding differences may apply):

toDouble(self, defaultValue: float=...) -> float

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#toDouble

toInt

toInt(defaultValue: int) -> int

X.toInt(defaultValue) -> int

Supplemental documentation: Qt 5 reference:

int QJsonValue::toInt(int defaultValue \= 0) const

Converts the value to an int and returns it.

If type() is not Double or the value is not a whole number, the defaultValue will be returned.

This function was introduced in Qt 5.2.

Upstream PySide2 reference signatures (binding differences may apply):

toInt(self, defaultValue: int=...) -> int

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#toInt

toObject

toObject(defaultValue: Any) -> Any

X.toObject(defaultValue) -> PythonQt.QtCore.QJsonObject

Supplemental documentation: Qt 5 reference:

QJsonObject QJsonValue::toObject(const QJsonObject \&defaultValue) const

Converts the value to an object and returns it.

If type() is not Object, the defaultValue will be returned.

QJsonObject QJsonValue::toObject() const

This is an overloaded function.

Converts the value to an object and returns it.

If type() is not Object, the QJsonObject() will be returned.

Upstream PySide2 reference signatures (binding differences may apply):

toObject(self) -> typing.Dict[str, PySide2.QtCore.QJsonValue]
toObject(self, defaultValue: typing.Dict[str, PySide2.QtCore.QJsonValue]) -> typing.Dict[str, PySide2.QtCore.QJsonValue]

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#toObject

toString

toString(defaultValue: Any) -> str

X.toString(defaultValue) -> str

Supplemental documentation: Qt 5 reference:

QString QJsonValue::toString() const

Converts the value to a QString and returns it.

If type() is not String, a null QString will be returned.

See also QString::isNull().

QString QJsonValue::toString(const QString \&defaultValue) const

Converts the value to a QString and returns it.

If type() is not String, the defaultValue will be returned.

Upstream PySide2 reference signatures (binding differences may apply):

toString(self) -> str
toString(self, defaultValue: str) -> str

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#toString

toVariant

toVariant() -> Any

X.toVariant() -> object

Supplemental documentation: Qt 5 reference:

QVariant QJsonValue::toVariant() const

Converts the value to a QVariant().

The QJsonValue types will be converted as follows:

Constant Description
Null QMetaType::Nullptr
Bool QMetaType::Bool
Double QMetaType::Double or QMetaType::LongLong
String QString
Array QVariantList
Object QVariantMap
Undefined QVariant()

See also fromVariant().

Upstream PySide2 reference signatures (binding differences may apply):

toVariant(self) -> typing.Any

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#toVariant

type

type() -> Any

X.type()

Supplemental documentation: Qt 5 reference:

QJsonValue::Type QJsonValue::type() const

Returns the type of the value.

See also QJsonValue::Type.

Upstream PySide2 reference signatures (binding differences may apply):

type(self) -> PySide2.QtCore.QJsonValue.Type

Source: https://doc.qt.io/archives/qt-5.15/qjsonvalue.html#type