GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Categories
  • Newsletter
  • Submit
  • Login
  • Awesome C++
  • JSON

This view

  • Original page
  • New address

GeezerVison is showing cpp.libhunt.com — qt-json Alternatives - C++ JSON | LibHunt

  • Subscribe
  • Submit
  • Categories
  • About
  • Login

qt-json

A simple class for parsing JSON data into a QVariant hierarchy and vice versa.

qt-json logo
DISCONTINUED. You can find some alternatives below.
Suggest Changes
Take the C++ Developer Survey - About 6 minutes on the tools, libraries and AI you use with C++. You get the results by email. Take the survey »
Popularity
3.8
Stable
Activity
0.0
Stable
Stars 331
Watchers 25
Forks 107
Last Commit almost 9 years ago

Code Quality Rank: L3
Programming language: C++
License: GNU General Public License v3.0 only
Tags: JSON    

qt-json alternatives and similar libraries

Based on the "JSON" category.
Alternatively, view qt-json alternatives based on common mentions on social networks and blogs.

  • json

    9.9 9.8 L1 qt-json VS json
    JSON for Modern C++
    nlohmann logo
  • RapidJSON

    9.5 0.0 L1 qt-json VS RapidJSON
    A fast JSON parser/generator for C++ with both SAX/DOM style API
    Tencent logo
  • SaaSHub - Software Alternatives and Reviews

    SaaSHub helps you find the best software and product alternatives
    Promo www.saashub.com
    SaaSHub Logo
  • simdjson

    9.5 9.5 qt-json VS simdjson
    Parsing gigabytes of JSON per second : used by Facebook/Meta Velox, the Node.js runtime, ClickHouse, WatermelonDB, Apache Doris, Milvus, StarRocks
    simdjson logo
  • cJSON

    9.4 3.9 L3 qt-json VS cJSON
    Ultralightweight JSON parser in ANSI C
    DaveGamble logo
  • JsonCpp

    9.1 7.8 L1 qt-json VS JsonCpp
    A C++ library for interacting with JSON.
    open-source-parsers logo
  • yaml-cpp

    8.7 8.1 qt-json VS yaml-cpp
    A YAML parser and emitter in C++
    jbeder logo
  • ArduinoJson

    8.6 5.1 qt-json VS ArduinoJson
    📟 JSON library for Arduino and embedded C++. Simple and efficient.
    bblanchon logo
  • JSMN

    7.8 0.0 L3 qt-json VS JSMN
    Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
    zserge logo
  • json-c

    7.8 8.7 qt-json VS json-c
    https://github.com/json-c/json-c is the official code repository for json-c. See the wiki for release tarballs for download. API docs at http://json-c.github.io/json-c/
    json-c logo
  • Jansson

    7.7 7.2 L2 qt-json VS Jansson
    C library for encoding, decoding and manipulating JSON data
    akheron logo
  • json11

    7.5 0.6 L2 qt-json VS json11
    DISCONTINUED. A tiny JSON library for C++11. [MIT]
  • YAJL

    7.0 0.0 L3 qt-json VS YAJL
    A fast streaming JSON parsing library in C.
    lloyd logo
  • LIBUCL

    6.2 8.1 L2 qt-json VS LIBUCL
    Universal configuration library parser
    vstakhov logo
  • json-parser

    6.0 5.3 L1 qt-json VS json-parser
    Very low footprint DOM-style JSON parser written in portable ANSI C
    json-parser logo
  • PicoJSON

    5.8 0.0 L1 qt-json VS PicoJSON
    a header-file-only, JSON parser serializer in C++
    kazuho logo
  • frozen

    5.1 2.6 L1 qt-json VS frozen
    JSON parser and generator for C/C++ with scanf/printf like interface. Targeting embedded systems.
    cesanta logo
  • json.h

    4.8 7.8 qt-json VS json.h
    🗄️ single header json parser for C and C++
    sheredom logo
  • JSON++

    4.7 0.0 L1 qt-json VS JSON++
    DISCONTINUED. A JSON parser in C++
  • QJson

    3.9 1.9 L1 qt-json VS QJson
    DISCONTINUED. QJson is a qt-based library that maps JSON data to QVariant objects.
    flavio logo
  • libjson

    3.8 1.4 L3 qt-json VS libjson
    a JSON parser and printer library in C. easy to integrate with any model.
    vincenthz logo
  • Boost.PropertyTree

    3.1 0.7 L1 qt-json VS Boost.PropertyTree
    Boost.org property_tree module
    boostorg logo
  • json_dto

    2.9 7.4 qt-json VS json_dto
    A small header-only library for converting data between json representation and c++ structs
    Stiffstream logo
  • JeayeSON

    2.8 0.0 L2 qt-json VS JeayeSON
    A very sane (header only) C++14 JSON library
    jeaye logo
  • json-voorhees

    2.7 9.3 L3 qt-json VS json-voorhees
    A killer modern C++ library for interacting with JSON.
    tgockel logo
  • StructMapping

    2.6 0.0 qt-json VS StructMapping
    Mapping json to and from a c++ structure
    bk192077 logo
  • Jsonifier

    2.4 4.7 qt-json VS Jsonifier
    A few classes for extremely fast json parsing/serializing in modern C++. Possibly the fastest json parser in C++. Possibly the fastest json serializer in C++.
    nihilai-collective logo
  • jute

    2.4 2.2 L3 qt-json VS jute
    Very simple C++ JSON Parser
    amir-s logo
  • ujson

    2.3 - qt-json VS ujson
    µjson is a a small, C++11, UTF-8, JSON library. [MIT]
  • iod.metajson

    2.0 0.0 qt-json VS iod.metajson
    Non-intrusive, high performance C++17 lightweight JSON de/serializer
    iodcpp logo
  • jvar

    1.8 0.0 qt-json VS jvar
    JS inspired Variants and JSON parsing for C++
    YasserAsmi logo
  • jbson

    1.8 0.0 L1 qt-json VS jbson
    JSON & BSON parser/writer
    chrismanning logo

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.

Do you think we are missing an alternative of qt-json or a related project?

Add another 'JSON' Library

Popular Comparisons

  • qt-json
    vs
    RapidJSON
  • qt-json
    vs
    JsonCpp
  • qt-json
    vs
    Boost.PropertyTree
  • qt-json
    vs
    QJson
  • qt-json
    vs
    Jansson

README

The qt-json project is a simple collection of functions for parsing and serializing JSON data to and from QVariant hierarchies.

NOTE: Qt5 introduced a native JSON object class. If you are targeting Qt5, you should use that instead.

HOW TO USE

Parsing JSON

The parser is really easy to use. Let's say we have the following QString of JSON data:

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

We would first call the parse-function:

#include "json.h"

bool ok;
// json is a QString containing the JSON data
QtJson::JsonObject result = QtJson::parse(json, ok).toMap();

if(!ok) {
  qFatal("An error occurred during parsing");

Assuming the parser completed without errors, we can then go through the hierarchy:

qDebug() << "encoding:" << result["encoding"].toString();
qDebug() << "plugins:";

foreach(QVariant plugin, result["plug-ins"].toList()) {
    qDebug() << "  -" << plugin.toString();
}

QtJson::JsonObject nested = result["indent"].toMap();
qDebug() << "length:" << nested["length"].toInt();
qDebug() << "use_space:" << nested["use_space"].toBool();

The previous code would print out the following:

encoding: "UTF-8"
plugins:
  - "python"
  - "c++"
  - "ruby"
length: 3
use_space: true
Serializing JSON

To write JSON data from Qt object is as simple as creating and assigning data to a QVariantMap/JsonObject:

QtJson::JsonObject contributor;
contributor["name"] = "Luis Gustavo";
contributor["age"] = 22;

QByteArray data = QtJson::serialize(contributor);

The byte array 'data' contains valid JSON data:

{
  "name": "Luis Gustavo",
  "age": 22
}
Serializing JSON pretty-print

By default, the serialization will create a minified version, like following:

{"name":"Luis Gustavo","age":22}

If you are debugging or logging, you may prefer to enable pretty-print mode globally, before serialize:

QtJson::setPrettySerialize(true);

QByteArray data = QtJson::serialize(contributor);
// ...
QByteArray data = QtJson::serialize(other_contributor);

Obviously, you can disable it with:

QtJson::setPrettySerialize(false);

After creating the QVariantMap, you can create a QVariantList/JsonArray and append the QVariantMaps.

QtJson::JsonObject friend1, friend2, friend3;
friend1["id"] = 1;
friend1["name"] = "Mackenzie Hamphrey";

friend2["id"] = 2;
friend2["name"] = "Melanie Molligan";

friend3["id"] = 3;
friend3["name"] = "Sydney Calhoun";

QtJson::JsonArray friends;
friends.append(friend1);
friends.append(friend2);
friends.append(friend3);

QtJson::JsonObject obj;
obj["friends"] = friends;

This way you create a nested structure:

{
    "friends": [
        {
            "id": 1,
            "name": "MackenzieHamphrey"
        },
        {
            "id": 2,
            "name": "MelanieMolligan"
        },
        {
            "id": 3,
            "name": "SydneyCalhoun"
        }
    ]
}

If you continue this process recursively, you nest more levels into the JSON structure.

Using Builders

For simplicity you can use builders, if you prefer.

For example, create a JsonObject:

QtJson::JsonObject json = QtJson::objectBuilder()
    ->set("field_1", 10)
    ->set("field_2", "A string")
    ->set("field_3", true)
    ->set("field_4", QtJson::objectBuilder()
        ->set("sub_field_1", 10.4)
        ->set("sub_field_n", "Another string")
    )
    ->create();

Or create a JsonArray:

QtJson::JsonArray json = QtJson::arrayBuilder()
    ->add(5)
    ->add(90.2)
    ->add(true)
    ->add("anything else")
    ->create();

Take a look at this example that rewrite the previous one:

QtJson::JsonObject obj = QtJson::objectBuilder()
    ->set("friends", QtJson::arrayBuilder()
        ->add(QtJson::objectBuilder()
            ->set("id", 1)
            ->set("name", "Mackenzie Hamphrey")
        )
        ->add(QtJson::objectBuilder()
            ->set("id", 2)
            ->set("name", "Melanie Molligan")
        )
        ->add(QtJson::objectBuilder()
            ->set("id", 3)
            ->set("name", "Sydney Calhoun")
        )
    )
    ->create();

3. CONTRIBUTING

Send in a pull request and bug the maintainer until it gets merged and published. Make sure to add yourself to AUTHORS.

Do not miss the trending, libraries, news and articles with our weekly report.

Awesome C++ is part of the LibHunt network. Terms. Privacy Policy.

(CC)
BY-SA
Spin The Wheel Of Names for a cryptographically secure random name picker.
Schedule a when to meet poll.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.