{"id":24381860,"url":"https://github.com/xeverous/fuser","last_synced_at":"2025-06-14T11:06:18.388Z","repository":{"id":136061559,"uuid":"260255695","full_name":"Xeverous/fuser","owner":"Xeverous","description":"Header-only library for automatic (de)serialization of C++ types to/from JSON.","archived":false,"fork":false,"pushed_at":"2020-05-02T19:12:28.000Z","size":21,"stargazers_count":53,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T00:06:27.695Z","etag":null,"topics":["cpp","cpp11","cpp14","cpp17","json","serialization","serialization-library"],"latest_commit_sha":null,"homepage":null,"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/Xeverous.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}},"created_at":"2020-04-30T15:57:53.000Z","updated_at":"2025-03-05T23:26:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"7eee1b7c-85dc-47b0-8e2a-815031c99fc7","html_url":"https://github.com/Xeverous/fuser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Xeverous/fuser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xeverous%2Ffuser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xeverous%2Ffuser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xeverous%2Ffuser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xeverous%2Ffuser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xeverous","download_url":"https://codeload.github.com/Xeverous/fuser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xeverous%2Ffuser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259804868,"owners_count":22913903,"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":["cpp","cpp11","cpp14","cpp17","json","serialization","serialization-library"],"created_at":"2025-01-19T09:13:41.646Z","updated_at":"2025-06-14T11:06:18.374Z","avatar_url":"https://github.com/Xeverous.png","language":"C++","readme":"# fuser\n\n1-file header-only library for automatic (de)serialization of C++ types to/from JSON.\n\n## how it works\n\nThe library has a predefined set of (de)serializers for common types:\n\n- `std::nullptr_t`\n- `bool`\n- all standard integer (`std::int*_t`, `std::uint*_t`) and floating-point (`float`, `double`, `long double`) numeric types (checks if the value fits into the destination type)\n- `char` is not explicitly implemented, but it will very likely fall into one of fixed-width integer types\n- `char8_t`, `char16_t` and `char32_t` are not implemented\n- `void*` and `void const*` (converts to `std::uintptr_t`)\n- `std::string`\n- `std::array\u003cT, N\u003e` (checks if array size matches)\n- `std::vector\u003cT\u003e`\n- `std::deque\u003cT\u003e`\n- `std::unique_ptr\u003cT\u003e` (outputs `null` when there is no value)\n- `std::optional\u003cT\u003e` (outputs `null` when there is no value)\n- `std::map\u003cK, V, C\u003e`\n- `std::unordered_map\u003cK, V, H, E\u003e`\n\nAdditionally, it supports (de)serializers for structures which are valid boost fusion sequences.\n\nNote that the above list is exactly how template specializations are implemented. The allocator template parameter is intentionally ommited because the current implementation has no guuarantees for stateful allocators. You can always define your (partial) specializations that reuse the existing serializers - just check how they are implemented.\n\nIf a type has no (de)serializer, the library will gracefully fail on a `static_assert`.\n\n## requirements\n\n- Boost \u003e= 1.56 (only header-only libraries)\n- [nlohmann/json](github.com/nlohmann/json) \u003e= 3.0\n- C++11\n- C++17 (optional, to enable `std::optional` support)\n- CMake \u003e= 3.13\n\n## example\n\n```cpp\n#include \u003cfuser/fuser.hpp\u003e\n\n#include \u003cvector\u003e\n#include \u003coptional\u003e\n#include \u003ciostream\u003e\n\nstruct my_struct\n{\n\tint i;\n\tdouble d;\n\tstd::optional\u003cbool\u003e b;\n};\n// note: fusion macros must be used in global scope\nBOOST_FUSION_ADAPT_STRUCT(my_struct, i, d, b)\n\nint main()\n{\n\tstd::vector\u003cmy_struct\u003e v = {\n\t\t{0, 3.14, {true}}, {1, 0.125, {false}}, {0, 0.0, {std::nullopt}}\n\t};\n\n\tstd::cout \u003c\u003c fuser::serialize(v).dump(4, ' ');\n}\n```\n\noutput:\n\n```json\n[\n    {\n        \"b\": true,\n        \"d\": 3.14,\n        \"i\": 0\n    },\n    {\n        \"b\": false,\n        \"d\": 0.125,\n        \"i\": 1\n    },\n    {\n        \"b\": null,\n        \"d\": 0.0,\n        \"i\": 0\n    }\n]\n```\n\n## library API\n\n### basic functions\n\n```cpp\nnamespace fuser {\n\ntemplate \u003ctypename T\u003e\nnlohmann::json serialize(T const\u0026 val);\n\ntemplate \u003ctypename T\u003e\nT deserialize(nlohmann::json const\u0026 json);\n\n}\n```\n\n### defining your own (de)serializer\n\n```cpp\ntemplate \u003c\u003e\nstruct fuser::serializer\u003cmy_type\u003e\n{\n\tstatic nlohmann::json serialize(my_type const\u0026 val)\n\t{\n\t\t/* ... */\n\t}\n};\n\ntemplate \u003c\u003e\nstruct fuser::deserializer\u003cmy_type\u003e\n{\n\tstatic my_type deserialize(nlohmann::json const\u0026 json)\n\t{\n\t\t/* ... */\n\t}\n};\n```\n\nBoth class templates have a second unused template parameter to allow easy SFINAE for specializations.\n\n## trivia\n\nThe library is named \"fuser\" because it is a simple merge of boost **fus**ion and **ser**ialization.\n\nSpecial thanks to [cycfi/json](https://github.com/cycfi/json) for the original idea.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeverous%2Ffuser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxeverous%2Ffuser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeverous%2Ffuser/lists"}