[Development] Proposal: JSON single value documents
newellm at blur.com
Mon Sep 12 23:40:19 CEST 2016
I would like to propose an addition to the QtJson api to allow single value
json documents (SVJ for brevity).
There have been various discussions regarding whether or not a SVJ is a valid
json document, with more recent rfc's saying yes. Here is one discussion
which also has links to others:
Regardless of whether a SJV is a valid document, the fact remains that to be
fully interoperable with many other existing projects Qt should support them.
My initial motivation is full support for the json/jsonb column type in
My proposed change would add the following methods to QJsonDocument:
bool isValue() const;
QJsonValue value() const;
void setValue(const QJsonValue &value);
The only backwards compatibility issue that i can think of would be that
fromVariant and fromJson will now return valid values documents. For that
reason it may be needed to provide new fromVariant and fromJson overloads.
I have figured out an elegant way to handle SVJ's without changing qt's binary
format. Because the binary format in it's current form can only hold a top-
level object or array, and because any old code will not be able to load a
binary document containing a single value, a version bump is required. My
idea is to have a SVJ stored as a single element json array containing the
value, but have the version set to 2. This results in no actual changes to
the binary format at all. Any non-SVJ document continues to use version 1
retaining full backwards compatibility for any document that was valid
Attached is a preliminary patch that compiles, passes the existing tests in
tests/auto/corelib/json, and adds a few new tests to exercise the new
If it's determined that this is a reasonable approach I will work on extending
the tests and updating the documentation.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 11868 bytes
Desc: not available
More information about the Development