mcpp index

compat.cjson

#include

Ultralightweight JSON parser in ANSI C

#include <cJSON.h>
mcpp add compat.cjson@1.7.19

Usage

From this repository's own test project — built and run by CI, not written for the website.

// Behavioral test: build a cJSON document, serialize, re-parse, assert fields.
#include <cJSON.h>
#include <cassert>
#include <cstring>

int main() {
    cJSON* root = cJSON_CreateObject();
    cJSON_AddNumberToObject(root, "answer", 42);
    cJSON_AddStringToObject(root, "lib", "cJSON");
    char* text = cJSON_PrintUnformatted(root);

    cJSON* parsed = cJSON_Parse(text);
    assert(parsed != nullptr);
    assert(cJSON_GetObjectItem(parsed, "answer")->valueint == 42);
    assert(std::strcmp(cJSON_GetObjectItem(parsed, "lib")->valuestring, "cJSON") == 0);

    cJSON_free(text);
    cJSON_Delete(root);
    cJSON_Delete(parsed);
    return 0;
}

tests/examples/cjson/tests/parse.cpp · project tests/examples/cjson

Build

targets
cjson (lib)
language
c++23
C standard
c99
import std
no
include dirs
*

Features

featuredeclares
utilssources

Sources (1)

  • */cJSON.c

Versions

VersionPlatforms Mirrorssha256
1.7.19 latest LinuxWindowsmacOS CN GLOBAL 7fa616e3046e…