[Development] State of "binary JSON" in 5.15+?

Thiago Macieira thiago.macieira at intel.com
Tue Apr 13 16:49:56 CEST 2021


On Tuesday, 13 April 2021 07:29:48 PDT Lars Knoll wrote:
> The binary JSON support is deprecated and only there for backwards
> compatibility. It had some issues (e.g. it couldn’t handle large JSON
> files), that’s why we deprecated it. It’s gone in Qt 6. I guess the docs
> need some adjustment though.

There's a QBinaryJsonDocument class that is not part of QtCore or qtbase that 
you can use to load your old documents and then extract data from, even save 
data to it again if you need to retain compatibility. The limitation of 128 MB 
maximum size remains.

QCborValue had a size limitation in 64-bit Qt 5 due to internally using 
QVector and QByteArray, so it couldn't deal have any array with more than 128 
* 2^20  elements or maps with half as many, or any arrays or objects where 
string content in that level added up to more than 2 GB. Those limitations are 
gone in Qt 6 and you'll run out of memory before you run into the limitations.

Parsing time of text JSON and CBOR is mostly the same and remains so from 
before the 5.15 switch of QJsonDocument's backend. They're all dominated by 
memory allocation. The big advantage of the binary JSON is that it made one 
huge allocation at the beginning equal to the size of the input, and in most 
cases that was just large enough for the binary data and would need no 
reallocation, with acceptable overhead. That overhead could be large if you 
had deeply-nested arrays and objects, with a lot of whitespace in your non-
compact JSON text form, though.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering





More information about the Development mailing list