Skip to content

empt1nesss/json-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-cpp

Overview

This library is a lightweight JSON tool for C++ that provides easy-to-use functions for reading, writing, and validating JSON data.

Features

  • Parsing: Converts JSON strings into C++ data structures.
  • Serialization: Converts C++ data structures back into JSON format.
  • Validation: Checks JSON data for proper syntax and structure, returning error messages when necessary.
  • Support for Complex Structures: Handles nested objects, arrays, and various data types (e.g., strings, numbers, booleans, null).

Requirements

Linking with CMake

Clone this repo to your third-party folder and add following lines to your CMakeLists.txt

add_subdirectory(third-party/json-cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE json-cpp)

Usage

Include the library header in your project and call the provided functions to parse, validate, and serialize JSON data.

Example code

#include <json.hpp>
#include <iostream>

int main() {
    std::string json_string = R"({"name": "John Doe", "age": 30, "is_student": false})";

    // Validate the JSON data
    std::string log;
    if (!Json::ValidateString(json_string, log)) {
        // Printing log if error occures
        std::cout << log << std::endl;
        return 1;
    }

    // Create a JSON tool instance
    Json j;

    // Parse the JSON string into an internal representation
    j.LoadFromString(json_string);

    // Serialize the object back to a JSON string
    std::string output = j.Serialize();
    std::cout << output << std::endl;

    return 0;
}

About

simple c++ lib for reading and writing json files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors