[Development] Proposal: JSON single value documents

Thiago Macieira thiago.macieira at intel.com
Tue Sep 13 03:31:40 CEST 2016


On segunda-feira, 12 de setembro de 2016 14:40:19 PDT Matt Newell wrote:
> My proposed change would add the following methods to QJsonDocument:
>   bool isValue() const;

I'm not sure it. Arrays and objects are JSON values, so this function would 
return a constant true, for all values, except when isEmpty() is true. Maybe 
we want isValid() instead.

These are ok:

>   QJsonValue value() const;
>   void setValue(const QJsonValue &value);

That would also mean the object()/setObject() and array()/setArray() pairs 
become convenience functions around value().to{Array,Object}() and setValue() 
with type constraining.

> 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.

Indeed.

> 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 previously.

Lars to comment.

> 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
> functionality.

And way too big (> 10 lines), so no one interested in this feature should open 
your patch and read it: it could become a problem if someone were to later 
implement it. Instead, please upload it to Gerrit so we can get your patch 
with the Contribution Licence Agreement.

> If it's determined that this is a reasonable approach I will work on
> extending the tests and updating the documentation.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list