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;
}
You can find the documentation here. If you want an offline version have a look here.
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.
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.
If you want to build the documentation
If you want to build the unit tests
At the root of the project run
mkdir build && cd build
cmake ..
make
The library can then be found in the following directory: build/lib/
.
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
.
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
.
- 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
Please keep in mind that this project was done a few years ago and that it doesn't meet my today's quality standards.