Skip to content

Krapaince/c_json_tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C JSON Tools

This project is a C library which provides tools to parse, edit and generate json file.

file.json:

{
    "nb": 34,
    "bool": true,
    "str": "string",
    "null": null,
    "obj": {},
    "arr": []
}
# A simple program which uses the library

#include <unistd.h>

#include <json/json.h>

int main(void)
{
    json_object_t* obj = json_object_parse_from_filepath("file.json");

    if (obj == NULL)
    {
        json_print_error(stdout);
        return 1;
    }
    json_object_generate_to_fd(obj, STDOUT_FILENO, NULL);
    json_object_destroy(obj);
    return 0;
}

📚 Documenation

You can find the documentation here. If you want an offline version have a look here.

Context

This project was realised during my second year of study at Epitech. It helps me build a network project that you can find here.

I have updated the library since so the version used in the network project is outdated.

⚠️ Warning

This project doesn't conform with RFC 7159. If you want a project that feat this usage, please see c-json.

The number type handle by the library has as limit the C integer. It does not support the floating and the base 10 exponent.

Prerequisites

If you want to build the documentation

If you want to build the unit tests

🔨 Build

⚠️ Before building anything, CMake's setup must be done

At the root of the project run

mkdir build && cd build
cmake ..

Build the library

make

The library can then be found in the following directory: build/lib/.

Build the documentation

ccmake .. # Then set the BUILD_DOC option on 'ON'
make Sphinx

The location of the generated documentation index can then be found here: build/doc/Sphinx/index.html.

Build the unit tests

make tests_run # To run the unit tests
make gcovr # To generate a coverage report

The generated coverage report is in the HTML format. The index can be found here: build/coverage/c_json_tools.html.

🐜 Know issues

  • Typedef ending with _t

Have a look here.

  • Parsing: json_*_parse_from_fd
{
    "a_json_object": 34
} Some extra characters after the final bracket

If there is characters after the fianl closing bracket, they will be read by the parser since it uses getline().

  • Documentation consistency

The function index page of the documentation doesn't use the same layout. During the creation of the documentation, I was testing two different approaches:

  • Documentation in header which will be extracted by Doxygen
  • Documentation in .rst file which will be parsed by Sphinx

⚠️ Notes

Please keep in mind that this project was done a few years ago and that it doesn't meet my today's quality standards.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors