Flesh out the repository with example and tests

This commit is contained in:
ktkk 2025-10-09 15:07:32 +00:00
parent 546eaa5d4d
commit 05c45bbc81
8 changed files with 165 additions and 57 deletions

22
example/CMakeLists.txt Normal file
View file

@ -0,0 +1,22 @@
add_executable(
example
main.c
)
set_target_properties(
example
PROPERTIES
C_STANDARD 23
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
)
target_link_libraries(
example
PRIVATE
json
)
target_include_directories(
example
PRIVATE
${CMAKE_SOURCE_DIR}
)

26
example/main.c Normal file
View file

@ -0,0 +1,26 @@
#include <stdio.h>
#include <json.h>
int main()
{
auto json = json_init(stdout, INDENT_2);
json_begin_object(&json);
{
json_add_object_field(&json, "array");
json_begin_array(&json);
{
json_add_string(&json, "element");
json_add_long(&json, 5l);
json_add_double(&json, 3.14);
json_add_bool(&json, true);
json_add_null(&json);
}
json_end_array(&json);
}
json_end_object(&json);
json_free(&json);
}