Skip to content

MericLuc/minijson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

miniJSON

🌟 A lightweight C++ wrapper around libjson-c 🌟

Just an easy-to-use C++ JSON library.

It wraps libjson-c and is therefore easily extendable to fit your needs.

How to use

  • CMakeLists.txt
cmake_minimum_required(VERSION 3.11)

project(miniJSON_example)

set(CMAKE_CXX_STANDARD          17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(miniJSON REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} miniJSON)
  • main.cpp
#include <miniJSON/JSON.h>
#include <iostream>

using namespace JSON;

int main(/*int argc, char* argv[]*/) {

    auto obj{ Object::newObject() };
    auto arr{ Object::newArray(3) };

    arr.append(Object::fromStr("{'str':'str'}"));
    arr.insert(1, Object::newString("JSON"));
    arr.erase(2);

    obj.insert("Hello"  , Object::newString("world!\n"));
    obj.insert("GoodBye", Object::newInt(42));
    obj.insert("arr"    , arr);
    

    std::cout << obj.toStr() << std::endl;
    // { "Hello": "world!\n", "GoodBye": 42, "arr": [ { "str": "str" }, "JSON" ] }


    return EXIT_SUCCESS;
}

How to install

  • Install
cmake [-S ${path/to/src}] [-DCMAKE_NSTALL_PREFIX=${install/prefix}] .
make
make install
  • Uninstall
make uninstall
  • Configuration options
name type description default value
BUILD_SHARED_LIBS boolean Build miniJSON as a shared library ON
BUILD_EXAMPLE boolean Also build provided usage example OFF

Dependencies

miniJSON depends on :

About

Lightweight cpp wrapper around json-c

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published