{"id":40071496,"url":"https://github.com/uskr/jsonrpc-lean","last_synced_at":"2026-01-19T08:30:38.906Z","repository":{"id":43923552,"uuid":"42411395","full_name":"uskr/jsonrpc-lean","owner":"uskr","description":"Lightweight, fast, transport-agnostic, c++ implementation of the JSON-RPC 2.0 specification","archived":false,"fork":false,"pushed_at":"2021-11-12T01:40:14.000Z","size":72,"stargazers_count":55,"open_issues_count":1,"forks_count":23,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-03-11T22:05:49.342Z","etag":null,"topics":["cpp","json-rpc"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uskr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-13T20:19:21.000Z","updated_at":"2023-01-29T02:46:10.000Z","dependencies_parsed_at":"2022-09-08T14:01:20.117Z","dependency_job_id":null,"html_url":"https://github.com/uskr/jsonrpc-lean","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/uskr/jsonrpc-lean","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uskr%2Fjsonrpc-lean","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uskr%2Fjsonrpc-lean/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uskr%2Fjsonrpc-lean/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uskr%2Fjsonrpc-lean/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uskr","download_url":"https://codeload.github.com/uskr/jsonrpc-lean/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uskr%2Fjsonrpc-lean/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28564008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T03:31:16.861Z","status":"ssl_error","status_checked_at":"2026-01-19T03:31:15.069Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","json-rpc"],"created_at":"2026-01-19T08:30:38.834Z","updated_at":"2026-01-19T08:30:38.899Z","avatar_url":"https://github.com/uskr.png","language":"C++","readme":"\n# jsonrpc-lean\n# version: 1.1.0\n\nAn [LGPL](https://www.gnu.org/licenses/lgpl-3.0.en.html) licensed, client/server, transport-agnostic, JSON-RPC library for C++.\n\nThe initial jsonrpc-lean implementation is derived from xsonrpc (https://github.com/erijo/xsonrpc) by Erik Johansson (https://github.com/erijo/). Many thanks to him.\n\nThe main idea behind branching xsonrpc and building a new project is to have a simple, transport-agnostic, header-only implementation, with as little external dependencies as possible. \n\nAnyone can use this lib by just adding the include folder to their include path and they are good to go.\n\nCurrently, the only dependency is rapidjson (https://github.com/Tencent/rapidjson), which is also a header-only implementation. Add rapidjson to your include path, and done.\n\nAnother advantage of removing the dependencies is that now it is easy to compile and use on most platforms that support c++, without much work.\n\n## Examples\n\nA simple server that process JSON-RPC requests:\n\n```C++\n#include \"jsonrpc-lean/server.h\"\n\nclass Math {\npublic:\n\tint Add(int a, int b) {\n\t\treturn a + b;\n\t}\n\n\tint64_t AddArray(const jsonrpc::Value::Array\u0026 a) {\n\t\treturn std::accumulate(a.begin(), a.end(), int64_t(0),\n\t\t\t[](const int64_t\u0026 a, const jsonrpc::Value\u0026 b) { return a + b.AsInteger32(); });\n\t};\n};\n\nstd::string Concat(const std::string\u0026 a, const std::string\u0026 b) {\n\treturn a + b;\n}\n\njsonrpc::Value::Struct ToStruct(const jsonrpc::Value::Array\u0026 a) {\n\tjsonrpc::Value::Struct s;\n\tfor (size_t i = 0; i \u003c a.size(); ++i) {\n\t\ts[std::to_string(i)] = jsonrpc::Value(a[i]);\n\t}\n\treturn s;\n}\n\nvoid PrintNotification(const std::string\u0026 a) {\n    std::cout \u003c\u003c \"notification: \" \u003c\u003c a \u003c\u003c std::endl;\n}\n\nint main() {\n\tMath math;\n\tjsonrpc::Server server;\n\t\n\tjsonrpc::JsonFormatHandler jsonFormatHandler;\n\tserver.RegisterFormatHandler(jsonFormatHandler);\n\n\tauto\u0026 dispatcher = server.GetDispatcher();\n\t// if it is a member method, you must use this 3 parameter version, passing an instance of an object that implements it\n\tdispatcher.AddMethod(\"add\", \u0026Math::Add, math);\n\tdispatcher.AddMethod(\"add_array\", \u0026Math::AddArray, math); \n\t\n\t// if it is just a regular function (non-member or static), you can you the 2 parameter AddMethod\n\tdispatcher.AddMethod(\"concat\", \u0026Concat);\n\tdispatcher.AddMethod(\"to_struct\", \u0026ToStruct);\n\tdispatcher.AddMethod(\"print_notification\", \u0026PrintNotification);\n\n\t// on a real world, these requests come from your own transport implementation (sockets, http, ipc, named-pipes, etc)\n\tconst char addRequest[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"add\\\",\\\"id\\\":0,\\\"params\\\":[3,2]}\";\n\tconst char concatRequest[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"concat\\\",\\\"id\\\":1,\\\"params\\\":[\\\"Hello, \\\",\\\"World!\\\"]}\";\n\tconst char addArrayRequest[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"add_array\\\",\\\"id\\\":2,\\\"params\\\":[[1000,2147483647]]}\";\n\tconst char toStructRequest[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"to_struct\\\",\\\"id\\\":5,\\\"params\\\":[[12,\\\"foobar\\\",[12,\\\"foobar\\\"]]]}\";\n\tconst char printNotificationRequest[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"method\\\":\\\"print_notification\\\",\\\"params\\\":[\\\"This is just a notification, no response expected!\\\"]}\";\n\n\tstd::shared_ptr\u003cjsonrpc::FormattedData\u003e outputFormattedData;\n    std::cout \u003c\u003c \"request: \" \u003c\u003c addRequest \u003c\u003c std::endl;\n    outputFormattedData = server.HandleRequest(addRequest);\n    std::cout \u003c\u003c \"response: \" \u003c\u003c outputFormattedData-\u003eGetData() \u003c\u003c std::endl;\n\n    outputFormattedData.reset();\n    std::cout \u003c\u003c \"request: \" \u003c\u003c concatRequest \u003c\u003c std::endl;\n    outputFormattedData = server.HandleRequest(concatRequest);\n    std::cout \u003c\u003c \"response: \" \u003c\u003c outputFormattedData-\u003eGetData() \u003c\u003c std::endl;\n\n    outputFormattedData.reset();\n    std::cout \u003c\u003c \"request: \" \u003c\u003c addArrayRequest \u003c\u003c std::endl;\n    outputFormattedData = server.HandleRequest(addArrayRequest);\n    std::cout \u003c\u003c \"response: \" \u003c\u003c outputFormattedData-\u003eGetData() \u003c\u003c std::endl;\n\n    outputFormattedData.reset();\n    std::cout \u003c\u003c \"request: \" \u003c\u003c toStructRequest \u003c\u003c std::endl;\n    outputFormattedData = server.HandleRequest(toStructRequest);\n    std::cout \u003c\u003c \"response: \" \u003c\u003c outputFormattedData-\u003eGetData() \u003c\u003c std::endl;\n\t\n\toutputFormatedData.reset();\n    std::cout \u003c\u003c \"request: \" \u003c\u003c printNotificationRequest \u003c\u003c std::endl;\n    outputFormatedData = server.HandleRequest(printNotificationRequest);\n    std::cout \u003c\u003c \"response size: \" \u003c\u003c outputFormatedData-\u003eGetSize() \u003c\u003c std::endl;\n\n\treturn 0;\n}\n```\n\nA client capable of generating requests for the server above could look like this:\n\n```C++\n#include \"jsonrpc-lean/client.h\"\n\nint main(int argc, char** argv) {\n\n\tconst char addResponse[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"id\\\":0,\\\"result\\\":5}\";\n    const char concatResponse[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"id\\\":1,\\\"result\\\":\\\"Hello, World!\\\"}\";\n    const char addArrayResponse[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"id\\\":2,\\\"result\\\":2147484647}\";\n    const char toStructResponse[] = \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"id\\\":4,\\\"result\\\":{\\\"0\\\":12,\\\"1\\\":\\\"foobar\\\",\\\"2\\\":[12,\\\"foobar\\\"]}}\";\n\n    std::unique_ptr\u003cjsonrpc::FormatHandler\u003e formatHandler(new jsonrpc::JsonFormatHandler());\n\tjsonrpc::Client client(*formatHandler);\n\n\tstd::shared_ptr\u003cFormattedData\u003e jsonRequest = client.BuildRequestData(\"add\", 3, 2);\n\tstd::cout \u003c\u003c jsonRequest-\u003eGetData(); // this will output the json-rpc request string\n\tjsonrpc::Response parsedResponse = client.ParseResponse(addResponse);\n    std::cout \u003c\u003c \"Parsed response: \" \u003c\u003c parsedResponse.GetResult().AsInteger32() \u003c\u003c std::endl \u003c\u003c std::endl;\n\t\n\tjsonRequest.reset(client.BuildRequestData(\"concat\", \"Hello, \", \"World!\"));\n\tstd::cout \u003c\u003c jsonRequest-\u003eGetData();\n\tparsedResponse = client.ParseResponse(concatResponse);\n        std::cout \u003c\u003c \"Parsed response: \" \u003c\u003c parsedResponse.GetResult().AsString() \u003c\u003c std::endl \u003c\u003c std::endl;\n\n\tjsonrpc::Request::Parameters params;\n\t{\n\t\tjsonrpc::Value::Array a;\n\t\ta.emplace_back(1000);\n\t\ta.emplace_back(std::numeric_limits\u003cint32_t\u003e::max());\n\t\tparams.push_back(std::move(a));\n\t}\n\tjsonRequest.reset(client.BuildRequestData(\"add_array\", params));\n\tstd::cout \u003c\u003c jsonRequest-\u003eGetData(); \n\tparsedResponse = client.ParseResponse(addArrayResponse);\n    std::cout \u003c\u003c \"Parsed response: \" \u003c\u003c parsedResponse.GetResult().AsInteger64() \u003c\u003c std::endl \u003c\u003c std::endl;\n\n\tparams.clear();\n\t{\n\t\tjsonrpc::Value::Array a;\n\t\ta.emplace_back(12);\n\t\ta.emplace_back(\"foobar\");\n\t\ta.emplace_back(a);\n\t\tparams.push_back(std::move(a));\n\t}\n\tjsonRequest.reset(client.BuildRequestData(\"to_struct\", params));\n\tstd::cout \u003c\u003c jsonRequest-\u003eGetData(); \n\tparsedResponse = client.ParseResponse(toStructResponse);\n\tauto structValue = parsedResponse.GetResult().AsStruct();\n\tstd::cout \u003c\u003c \"Parsed response: \" \u003c\u003c std::endl;\n\tstd::cout \u003c\u003c \"   0 : \" \u003c\u003c structValue[\"0\"].AsInteger32() \u003c\u003c std::endl;\n\tstd::cout \u003c\u003c \"   1 : \" \u003c\u003c structValue[\"1\"].AsString() \u003c\u003c std::endl;\n\tstd::cout \u003c\u003c \"   2 : [\" \u003c\u003c structValue[\"2\"].AsArray()[0] \u003c\u003c \", \" \u003c\u003c structValue[\"2\"].AsArray()[1] \u003c\u003c \"]\" \u003c\u003c std::endl;\n\t\n\tjsonRequest.reset(client.BuildNotificationData(\"print_notification\", \"This is just a notification, no response expected!\"));\n\tstd::cout \u003c\u003c jsonRequest-\u003eGetData();\n\n    return 0;\n}\n```\n\n## Usage Requirements\n\nTo use jsonrpc-lean on your project, all you need is:\n\n* A C++ compiler (GCC 5.0+ (Linux), XCode/Clang (OSX 10.7+), MSVC 14.0+ (Visual Studio 2015))\n* [rapidjson](https://github.com/Tencent/rapidjson) (Only need the include folder on your include path, don't worry about compiling it)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuskr%2Fjsonrpc-lean","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuskr%2Fjsonrpc-lean","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuskr%2Fjsonrpc-lean/lists"}