11#include <QJsonDocument>
21 return QJsonDocument::fromVariant (var)
22 .toJson (compact ? QJsonDocument::Compact : QJsonDocument::Indented);
27 QFile file { filename };
28 if (!file.open (QIODevice::WriteOnly))
30 qWarning () <<
"unable to open file" << file.fileName () <<
"for writing:" << file.errorString ();
31 return Left { file.errorString () };
36 qWarning () <<
"unable to write to file" << file.fileName () <<
":" << file.errorString ();
37 return Left { file.errorString () };
Either< QString, Void > SerializeJsonToFile(const QString &filename, const QVariant &var, bool compact)
QByteArray SerializeJson(const QVariant &var, bool compact)
Serializes the given var to JSON representation.
A proper void type, akin to unit (or ()) type in functional languages.