[Development] Json support for QtCore

lars.knoll at nokia.com lars.knoll at nokia.com
Sun Dec 11 15:55:51 CET 2011


Hi Sivan,

On 12/11/11 10:39 AM, "ext Sivan Greenberg" <sivan at omniqueue.com> wrote:

>Hi Lars!
>
>On Sat, Dec 10, 2011 at 11:32 PM,  <lars.knoll at nokia.com> wrote:
>> there were quite a few discussions and requests over the last months to
>> add Json support as part of QtCore, and maybe integrating one of the
>> existing parsers.
>
>There were also discussions and even a couple of bug report about
>adding "native" (a'la making Json first class citizen) support to QML
>as well (I guess this means adding it to the QDeclerativeContext
>engine?) , in favor of having one implementation that'd be standard
>and fast - https://bugreports.qt.nokia.com/browse/QTBUG-12117 .

That might make sense, but would need some further discussion on how to
best do it. I have some ideas, but need to validate this with the QML and
V8 experts :)
>
>>
>> I was however never really happy with them. Mainly because they all
>>parse
>> into a QVariant(Map), and don't offer any real API to create and modify
>> Json. In addition, I believed that it was possible to create a faster
>> parser, and wanted to have a binary representation for the parsed Json.
>>
>I wonder if the QML implementation in the bug report would suffer from
>the same (or perhaps worse?) performance issues?

If it uses qjson behind the scenes it'll be a lot slower than it has to be
(see my post a few minutes ago).
>
>> So I sat down over the last weeks and implemented hacked on something on
>> my own. You can see the current state in our first playground project
>>that
>> Sergio created for me yesterday. You can clone it from
>> 
>>ssh://username@codereview.qt-project.org:29418/playground/qtbinaryjson.gi
>>t
>>
>
>So, could be bind this to have an QML "native" JSON implementation and
>handling? Perhaps also to tie it in to have a JsonModel just as the
>XmlListModel uses XML?

It's possible. The main question will be how to inject it into QML without
converting the data.
>
>> Things look rather promising, and I consider the code to be mostly
>>feature
>> complete. There's work to be done on the API, and documentation is still
>> completely missing, but most of the other pieces are there.
>>
>/me keen to find a spare weekend to check this out.
>
>> What I have right now:
>>
>> * A binary representation of Json, that can be simply mmap'ed from a
>>file,
>> or copied around. This gives us an extremely cheap way to load and save
>> Json objects in binary form.
>
>Would this enable us to store complete binary chunks (files, network
>dumps etc..) as BSON allows? I have some use cases for this if this is
>possible.

You can simply dump the whole Json object to a file and reread it from
there at basically zero cost.
>
>>
>> The binary representation is optimized for fast reading. The binary
>>format
>> is relatively compact and stores the whole object in one blob.
>
>Is this a standard binary format of JSON, or something of your own devise?

It's something I wrote. I wanted it to be something that you can simply
mmap from a file and use without ever having to parse anything to make
saving and restoring of json objects as cheap as possible.

The problem with bson is that it's a streaming format that still requires
parsing and as such was unsuitable for some of the use cases I have.
>
>> There's a bit of work still required to finish it, but I would like to
>> start the discussion about including it into QtCore anyways. I'd also be
>> happy about any feedback.
>
>Many thanks for this!

You're welcome :)

Cheers,
Lars




More information about the Development mailing list