View on GitHub

QSON

Fast and simple JSON manipulation in Qt.

Download this project as a .zip file Download this project as a tar.gz file

What's this?

A fast way to manipulate JSON data from Qt/C++ apps under the MIT license.

Why is this any better than QJson?

Because QJson has about ~2,200 lines of code (including ~960 lines of Bison-generated code). QSON has just about 480 lines of code, created by hand.

(The lines of code were counted by running CLOC on the source directories of the projects.)

Is the API different than QJson's API?

Yes. QSON's API is designed for ease of use and code readability. To read the following JSON...

{
"encoding" : "UTF-8",
"plug-ins" : [
    "python",
    "c++",
    "ruby"
    ],
"indent" : { "length" : 3, "use_space" : true }
}

...while using QJson, you would have to do something like this at the least:

QJson::Parser parser;
bool* ok;
QVariantMap result = parser.parse("{ ...jsondata... }", &ok).toMap();
int length = result["indent"].toMap()["length"].toInt();

But if you use QSON you only have to do the following:

QsonDoc* jsonDoc = new QsonDoc();
jsonDoc->readFile("json_file.json");
int length = jsonDoc->at("indent")->at("length")->toInt();

Writing a document is just as easy:

QsonDoc* jsonDoc = new QsonDoc();
/* ... do something here to add stuff to the doc ... */
QString json = jsonDoc->writeJSON();

You could also call writeFile("filename") to write output to a file instead of returning it.