{"id":15047632,"url":"https://github.com/alexistm/cracon","last_synced_at":"2026-02-13T10:40:02.310Z","repository":{"id":242682573,"uuid":"807138074","full_name":"AlexisTM/cracon","owner":"AlexisTM","description":"Craft Configuration with ease, C++17","archived":false,"fork":false,"pushed_at":"2024-06-06T16:50:53.000Z","size":414,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T17:17:06.276Z","etag":null,"topics":["configuration","cpp","cpp17","craft","easy-to-use","json","modern"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexisTM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-28T14:48:42.000Z","updated_at":"2024-06-06T16:50:56.000Z","dependencies_parsed_at":"2024-06-04T12:26:50.890Z","dependency_job_id":"90253653-ea6c-4ada-a25e-91decfc9ef86","html_url":"https://github.com/AlexisTM/cracon","commit_stats":null,"previous_names":["alexistm/flacon"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexisTM%2Fcracon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexisTM%2Fcracon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexisTM%2Fcracon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexisTM%2Fcracon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexisTM","download_url":"https://codeload.github.com/AlexisTM/cracon/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243489777,"owners_count":20298997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","cpp","cpp17","craft","easy-to-use","json","modern"],"created_at":"2024-09-24T21:01:41.030Z","updated_at":"2026-02-13T10:40:02.232Z","avatar_url":"https://github.com/AlexisTM.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cracon, Craft your configuration!\n\n![cracon uwu logo](doc/img/cracon.jpg)\n\n**Cracon** is a lightweight C++ library for handling _JSON_ configuration files. It provides a simple and intuitive API for reading, writing configurations. It outputs two files, one `default` with all defaults parameters set in the code, and one for changed parameters.\n\nIt supports (tested for):\n* booleans\n* enums\n* (u)int(00)_t\n* float/double\n* std::vector\n* std::string\n* std::array\n\nMost of the heavy lifting is done by [Niels Lohmann's awesome JSON library](https://json.nlohmann.me).\n\n## Features\n\n* **Easy** to use\n* Somewhat **Type-safe** (it is still JSON)\n* **JSON** format to be human readable\n* Defaults are defined **in the code**\n* Defaults are **reported** to allow review of the defaults in CI/CD\n* Defaults are **not mangled** to the actual configuration to allow to modify defaults who were not explicitly modified\n* Only variations are in the json file\n\n## Build \u0026 test\n\n```bash\n# For Linux\ngit clone https://github.com/AlexisTM/cracon\nmkdir cracon/build \u0026\u0026 cd cracon/build\ncmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON\ncmake --build .\n# For Windows\ncmake --build . --config Release\n\nctest\n```\n\n## API\n\n### Basic usage\n\n```cpp\nauto config = cracon::File(\"config.json\", \"defaults.json\");\n// Or config.init(\"config.json\", \"defaults.json\")\n\nint int_value = config.get(\"/int\", 1);\nauto some_string = config.get\u003cstd::string\u003e(\"/oh/hi\", \"mark\");\nauto a_vector = config.get\u003cstd::vector\u003cfloat\u003e\u003e(\"/vector\", {1., 2., 3.});\n\nint_value = config.set(\"/int\", 42);\nif(config.should_write()) { // Only write it if there is a change\n  config.write();\n}\n```\n\nWill result in:\n\n```json\n// \"defaults.json\"\n{\n  \"int\": 1,\n  \"oh\": { \"hi\": \"mark\" },\n  \"data\": [1.0, 2.0, 3.0]\n}\n\n// config.json\n{\n  \"int\": 42,\n}\n```\n\n### Parameters and groups\n\nGroups avoids typos when repeating the same namespace multiple times.\nParameters wraps a value to use a single line to read/write a parameter and avoids repeating the accessor/key.\n\nBoth groups and parameters keep a shared_ptr to the File, which is initially created by the SharedFile.\n\n```c++\nclass Car {\n public:\n  Car(cracon:: SharedFile:: Group config) {\n\n    speed = config.get_param\u003cint64_t\u003e(\"speed\", 9000);\n    horsepower = config.get_param\u003cint64_t\u003e(\"horsepower\", 120);\n    motor_curve = config.get_param\u003cstd::array\u003cint, 24\u003e\u003e(\"motor_curve\", {});\n\n  }\n\n  cracon:: SharedFile:: Param\u003cint64_t\u003e speed;\n  cracon:: SharedFile:: Param\u003cint64_t\u003e horsepower;\n  cracon:: SharedFile:: Param\u003cstd::array\u003cint, 24\u003e\u003e motor_curve;\n};\n\nint main() {\n  auto config = cracon:: SharedFile(\"config.json\", \"defaults.json\");\n  Car car = Car(config.get_group(\"car\"));\n  car.speed.set(1000);\n  config.write();\n}\n\n```\n\n## Debugging\n\nBuild this project with `-DCRACON_ENABLE_LOG=ON` to enable logging.\n\n```\n\n$ ./cracon_basic_usage.exe\n[cracon] [INFO] The requested key doesn't exist for /oh/hi defaulted to \"mark\". Error: [json.exception.out_of_range.403] key 'oh' not found\n[cracon] [INFO] The requested key doesn't exist for /vector defaulted to [1.0, 2.0, 3.0]. Error: [json.exception.out_of_range.403] key 'vector' not found\n\n```\n\n## Integration in your project\n\nThis library uses [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) for dependency management. This permits many other usage, see [examples/cmake...](examples/) for different integrations.\n\n```cmake\ninclude(cmake/CPM.cmake)\nCPMAddPackage(\n  NAME cracon\n  GITHUB_REPOSITORY alexistm/cracon\n  GIT_TAG main\n  VERSION 0.0.1\n  OPTIONS \"BUILD_EXAMPLES OFF\" \"BUILD_TESTING OFF\"\n)\n\nadd_executable(${PROJECT_NAME} main.cpp)\ntarget_include_directories(${PROJECT_NAME} PUBLIC\n  $\u003cBUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include\u003e\n  $\u003cINSTALL_INTERFACE:include\u003e)\n\ntarget_link_libraries(${PROJECT_NAME} cracon)\n\ninstall(\n  TARGETS ${PROJECT_NAME}\n  EXPORT export_${PROJECT_NAME}\n  ARCHIVE DESTINATION lib\n  LIBRARY DESTINATION lib\n  RUNTIME DESTINATION bin\n)\n```\n\n## Considerations\n\n* If `File::get` is called multiple times, only the last call defines the default. Call `File::get` once for consistency or use `Param::get` which won't reparse the data each time. This check was not added as it increases the overhead significantly if it is called often/big configuration files.\n* `set` does not write to the defaults\n\n## Contributing\n\nContributions to Cracon are welcome! Feel free to open issues, submit pull requests, or provide feedback. Especially if you are a CMake Guru and knows how to ensure this is as easy to integrate as possible.\n\n## License\n\nCracon is released under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexistm%2Fcracon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexistm%2Fcracon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexistm%2Fcracon/lists"}