[Development] json api for modifying document

Girish Ramakrishnan girish at forwardbias.in
Thu May 10 16:58:59 CEST 2012


Hi,

On Thu, May 10, 2012 at 12:21 AM,  <lars.knoll at nokia.com> wrote:
> On 5/10/12 5:59 AM, "ext Girish Ramakrishnan" <girish at forwardbias.in>
> wrote:
>
>>Hi Lars,
>>The current API appears to make modifications to values instead of the
>>document itself. This makes it quite cumbersome to modify a document.
>>For example, to change the value of 5 to 10 in the json "[1, 2, [3, 4,
>>[5, 6]]]", one has to write the following code.
>>
>>    QJsonDocument doc = QJsonDocument::fromJson("[1, 2, [3, 4, [5, 6]]]");
>>    QJsonArray a1 = doc.array();
>>    QJsonArray a2 = a1[2].toArray();
>>    QJsonArray a3 = a2[2].toArray();
>>
>>    a3[0] = 10;
>>    a2[2] = a3;
>>    a1[2] = a2;
>>
>>AFAICT, to change a value somewhere in the document, one has to update
>>and then update all the way up.
>
> Yes, the API is following implicit sharing paradigms as we have it most
> other places in Qt. The problem with modifying the document directly is
> that it'll be rather inefficient if you have to modify several values in
> the inner array.
>

True

>>So, if I didn't miss something, may I suggest that we make this like
>>the QWebElement API (which makes modifications to the DOM tree
>>in-place)?
>
> This is a very large behavioral change and IMO comes too late now. The
> jsondb module e.g. relies heavily on the QJson classes and such a change
> would silently break a lot of code there.
>
> One option I see is to add some API for 5.1 that returns references
> instead of values. We already have QJsonValueRef, maybe that scheme can be
> extended to also allow for references to arrays and objects.
>

https://bugreports.qt-project.org/browse/QTBUG-25723

Girish



More information about the Development mailing list