{"id":19164183,"url":"https://github.com/ichishino/jsonity","last_synced_at":"2026-06-30T13:32:13.086Z","repository":{"id":16324706,"uuid":"19073924","full_name":"Ichishino/JSonity","owner":"Ichishino","description":"JSON parser and generator for C++","archived":false,"fork":false,"pushed_at":"2017-03-18T06:06:45.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-22T23:11:59.894Z","etag":null,"topics":["c-plus-plus","header-only","json-parsing","json-string"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ichishino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-23T15:02:02.000Z","updated_at":"2022-07-06T01:11:47.000Z","dependencies_parsed_at":"2022-08-04T09:00:21.569Z","dependency_job_id":null,"html_url":"https://github.com/Ichishino/JSonity","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Ichishino/JSonity","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ichishino%2FJSonity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ichishino%2FJSonity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ichishino%2FJSonity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ichishino%2FJSonity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ichishino","download_url":"https://codeload.github.com/Ichishino/JSonity/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ichishino%2FJSonity/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34969682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-30T02:00:05.919Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["c-plus-plus","header-only","json-parsing","json-string"],"created_at":"2024-11-09T09:19:15.931Z","updated_at":"2026-06-30T13:32:13.002Z","avatar_url":"https://github.com/Ichishino.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSonity\r\n=======\r\n\r\nJSonity is JSON utility for C++\r\n\r\n## Features\r\n* JSON Parsing and Serializing.\r\n* Serializing User Objects into JSON string.\r\n* Serializing STL (map, vector, list, ...) into JSON string directly.\r\n* Support Unicode (wchar_t, char16_t, char32_t).\r\n* Support I/O stream interface.\r\n* One header file only.\r\n* Simple easy interface.\r\n\r\n## Examples\r\n\r\n```c++\r\n\r\n// If using \u003cstd::list, set, deque, array, forward_list, ...\u003e\r\n// Include them before \"jsonity.hpp\"\r\n//\r\n// #include \u003clist\u003e\r\n// ...\r\n\r\n#include \"jsonity.hpp\"\r\n\r\nusing namespace jsonity;\r\n```\r\n\r\n#### Parse JSON string\r\n\r\n```c++\r\n// example1_1\r\n\r\nstd::string jsonStr =\r\n    \"{\"\r\n        \"\\\"name1\\\": 100,\"\r\n        \"\\\"name2\\\": true,\"\r\n        \"\\\"name3\\\": [\"\r\n            \"10,\"\r\n            \"20,\"\r\n            \"30\"\r\n        \"],\"\r\n        \"\\\"name4\\\": \\\"data\\\"\"\r\n    \"}\";\r\n\r\nJson::Value v;\r\nJson::decode(jsonStr, v);   // parse\r\n\r\nsize_t size = v.getSize();  // 4\r\n\r\nbool check = v.hasName(\"name1\");  // true\r\n\r\nint n1 = (int)v[\"name1\"].getNumber(); // 100\r\nint n2 = v[\"name1\"];                  // 100\r\n\r\nbool b1 = v[\"name2\"].getBoolean(); // true\r\nbool b2 = v[\"name2\"];              // true\r\n\r\nJson::Array\u0026 arr1 = v[\"name3\"].getArray();\r\nJson::Array\u0026 arr2 = v[\"name3\"];\r\n\r\nsize_t array_size = v[\"name3\"].getSize();  // 3\r\n\r\nint arr_n1 = arr1[0];   // 10\r\nint arr_n2 = arr1[1];   // 20\r\nint arr_n3 = arr1[2];   // 30\r\n\r\nconst std::string\u0026 str1 = v[\"name4\"].getString();   // \"data\"\r\nconst std::string\u0026 str2 = v[\"name4\"];               // \"data\"\r\n\r\ntry\r\n{\r\n    b1 = v[\"name4\"].getBoolean(); // exception\r\n}\r\ncatch (const Json::TypeMismatchException\u0026)\r\n{\r\n    // type mismatch\r\n}\r\n```\r\n\r\n```c++\r\n// example1_2\r\n\r\nstd::string jsonStr = \"{ ... }\";\r\n\r\nJson::Error err;\t// error info\r\nJson::Value v;\r\n\r\nif (!Json::decode(jsonStr, v, \u0026err))\t// parse\r\n{\r\n\t// error\r\n\r\n\tprintf(\"Index: %d\\n\",\r\n\t\terr.getCursor().getPos() + 1);\r\n\r\n\tprintf(\"Line: %d Col: %d\\n\",\r\n\t\terr.getCursor().getRow() + 1,\r\n\t\terr.getCursor().getCol() + 1);\r\n}\r\n\r\n```\r\n\r\n```c++\r\n// example1_3\r\n\r\nstd::ifstream ifs(\"json.dat\", std::ios::in | std::ios::binary);\r\n\r\nJson::Value v;\r\nJson::decode(ifs, v);   // parse\r\n```\r\n\r\n```c++\r\n// example1_4\r\n\r\nstd::ifstream ifs(\"json.dat\", std::ios::in | std::ios::binary);\r\n\r\nJson::Value v;\r\nifs \u003e\u003e v;         // parse\r\n\r\nif (!ifs)\r\n{\r\n\t// error\r\n}\r\n\r\n```\r\n\r\n```c++\r\n// example1_5\r\n\r\nstd::string jsonStr =\r\n    \"{\"\r\n        \"\\\"name1\\\": {\"\r\n            \"\\\"data1\\\": [\"\r\n                \"-3.14,\"\r\n                \"\\\"aaaa\\\",\"\r\n                \"true,\"\r\n                \"{\"\r\n                    \"\\\"subdata1\\\": [\"\r\n                        \"600\"\r\n                    \"]\"\r\n                \"}\"\r\n            \"]\"\r\n        \"}\"\r\n    \"}\";\r\n\r\nJson::Value v;\r\nJson::decode(jsonStr, v);   // parse\r\n\r\ndouble d = v[\"name1\"][\"data1\"][0];    // -3.14\r\nconst std::string\u0026 str = v[\"name1\"][\"data1\"][1]; // \"aaaa\"\r\nbool b = v[\"name1\"][\"data1\"][2];      // \"true\"\r\nint n = v[\"name1\"][\"data1\"][3][\"subdata1\"][0];  // 600\r\n\r\nstd::list\u003cJson::Value\u003e listVal;\r\nv.findRecursive(\"subdata1\", listVal);\t// find recursively\r\n\r\nJson::Value\u0026 v2 = *listVal.begin();\r\n\r\nn = v2[0]; // 600\r\n\r\n```\r\n\r\n#### Serialize object to JSON string\r\n\r\n```c++\r\n// example2_1\r\n\r\nJson::Object root_obj;\r\n\r\nroot_obj[\"name1\"] = 100;\r\nroot_obj[\"name2\"] = true;\r\nroot_obj[\"name3\"] = \"data_string\";\r\nroot_obj[\"name4\"] = Json::null();\r\n\r\nJson::Array arr(3);\r\narr[0] = \"test\";\r\narr[1] = -400;\r\narr[2] = false;\r\n\r\nroot_obj[\"name5\"] = arr;\r\n\r\nJson::Object obj;\r\nobj[\"xxx\"] = -1.5;\r\nobj[\"yyy\"] = true;\r\nobj[\"zzz\"] = \"test_test\";\r\n\r\nroot_obj[\"name6\"] = obj;\r\n\r\nstd::list\u003cint\u003e list;  // any STL type (map, vector, list, set, ...)\r\nlist.push_back(444);\r\nlist.push_back(777);\r\n\r\nroot_obj[\"name7\"] = list;\r\n\r\nstd::string jsonStr;\r\nJson::encode(root_obj, jsonStr);  // serialize\r\n\r\n// jsonStr ==\r\n//  {\"name1\":100,\"name2\":true,\"name3\":\"data_string\",\"name4\":null,\r\n//  \"name5\":[\"test\",-400,false],\"name6\":{\"xxx\":-1.5,\"yyy\":true,\"zzz\":\"test_test\"},\r\n//  \"name7\":[444,777]}\"\r\n```\r\n\r\n```c++\r\n// example2_2\r\n\r\nJson::Object root_obj;\r\n\r\n...\r\n\r\nstd::ofstream ofs(\"json.dat\",\r\n\tstd::ios::out | std::ios::binary | std::ios::trunc);\r\n\r\nJson::encode(root_obj, ofs);  // serialize (redirect)\r\n```\r\n\r\n```c++\r\n// example2_3\r\n\r\nJson::Object root_obj;\r\n\r\n...\r\n\r\nstd::cout \u003c\u003c root_obj \u003c\u003c std::endl;  // serialize (redirect)\r\n```\r\n\r\n```c++\r\n// example2_4\r\n\r\n// User Object\r\nclass MyData : public Json::UserValue\u003cMyData\u003e\r\n{\r\npublic:\r\n    MyData(int data1, const std::string\u0026 data2)\r\n    {\r\n        data1_ = data1;\r\n        data2_ = data2;\r\n    }\r\n    MyData(const MyData\u0026 other)\r\n    {\r\n        data1_ = other.data1_;\r\n        data2_ = other.data2_;\r\n    }\r\n    ~MyData()\r\n    {\r\n    }\r\n\r\n    int getData1() const\r\n    {   return data1_;    }\r\n    const std::string\u0026 getData2() const\r\n    {   return data2_;    }\r\n\r\nprotected:\r\n\r\n    // Encode\r\n    virtual void encode(Json::EncodeContext\u0026 ctx) const\r\n    {\r\n        std::ostringstream oss;\r\n        oss \u003c\u003c data2_ \u003c\u003c \"-\" \u003c\u003c data1_;\r\n\r\n        Json::encodeString(ctx, oss.str());\r\n    }\r\n\r\nprivate:\r\n    int data1_;\r\n    std::string data2_;\r\n};\r\n\r\n\r\nJson::Object root_obj;\r\n\r\n// User Object\r\n\r\nMyData myData(99, \"777\");\r\nroot_obj[\"name1\"] = myData;\r\n\r\nMyData* myDataPtr = new MyData(55, \"AAA\");\r\nroot_obj[\"name2\"] = myDataPtr;\r\n\r\nstd::string jsonStr;\r\nJson::encode(root_obj, jsonStr);  // serialize\r\n\r\n// jsonStr == {\"name1\":\"777-99\",\"name2\":\"AAA-55\"}\r\n\r\ndelete myDataPtr;\r\n```\r\n\r\n```c++\r\n// example2_5\r\n\r\nstd::map\u003cstd::string, std::string\u003e map;  // any STL type (map, vector, list, set, ...)\r\n\r\nmap[\"name1\"] = \"data1\";\r\nmap[\"name2\"] = \"data2\";\r\nmap[\"name3\"] = \"data3\";\r\n\r\nstd::string jsonStr;\r\nJson::encode(map, jsonStr);  // serialize\r\n\r\n// jsonStr == {\"name1\":\"data1\",\"name2\":\"data2\",\"name3\":\"data3\"}\r\n```\r\n\r\n```c++\r\n// example2_6\r\n\r\nstd::map\u003cstd::string, std::list\u003cMyData\u003e \u003e map;  // any STL type (map, vector, list, set, ...)\r\n\r\n// User Object\r\n\r\nstd::list\u003cMyData\u003e list;\r\nlist.push_back(MyData(66, \"666\"));\r\nlist.push_back(MyData(77, \"777\"));\r\nlist.push_back(MyData(88, \"888\"));\r\n\r\nmap[\"name\"] = list;\r\n\r\nstd::string jsonStr;\r\nJson::encode(map, jsonStr);  // serialize\r\n\r\n// jsonStr == {\"name\":[\"666-66\",\"777-77\",\"888-88\"]}\r\n```\r\n\r\n```c++\r\n// example2_7\r\n\r\nstd::vector\u003cint\u003e list;  // any STL type (map, vector, list, set, ...)\r\n\r\nlist.push_back(100);\r\nlist.push_back(200);\r\nlist.push_back(300);\r\n\r\nstd::string jsonStr;\r\nJson::encode(list, jsonStr);  // serialize\r\n\r\n// jsonStr == [100,200,300]\r\n\r\n```\r\n\r\n```c++\r\n// example2_8\r\n\r\nstd::map\u003cstd::string, std::vector\u003cint\u003e \u003e map;\r\n\r\nstd::vector\u003cint\u003e vec(3);\r\nvec[0] = 100;\r\nvec[1] = 200;\r\nvec[2] = 300;\r\n\r\nmap[\"test\"] = vec;\r\n\r\nJson::EncodeStyle es1;\r\nes1.setStandardStyle();\r\n\r\nstd::string jsonStr1;\r\nJson::encode(map, jsonStr1, \u0026es1);  // serialize (Human Readable)\r\n\r\n/* jsonStr1 ==\r\n    {\r\n        \"test\": [\r\n            100,\r\n            200,\r\n            300\r\n        ]\r\n    }\r\n*/\r\n\r\nJson::EncodeStyle es2;\r\nes2.setQuat(true);\r\nes2.setPrintNewLine(true);\r\nes2.setEscapeCtrlChar(true);\r\nes2.setNewLine(true, false);\r\n\r\nstd::string jsonStr2;\r\nJson::encode(map, jsonStr2, \u0026es2);  // serialize (for C++ Program)\r\n\r\n/* jsonStr2 ==\r\n    \"{\\n\"\r\n        \"\\\"test\\\": [\\n\"\r\n            \"100,\\n\"\r\n            \"200,\\n\"\r\n            \"300\\n\"\r\n        \"]\\n\"\r\n    \"}\\n\"\r\n*/\r\n```\r\n\r\n#### Compare object to JSON string\r\n\r\n```c++\r\n// example3_1\r\n\r\nstd::string jsonStr =\r\n    \"{\"\r\n        \"\\\"aaa\\\": 100,\"\r\n        \"\\\"bbb\\\": \\\"data\\\"\"\r\n    \"}\";\r\n\r\nJson::Value v;\r\nJson::decode(jsonStr, v);\r\n\r\nbool result = Json::equal(v, jsonStr);  // true\r\n```\r\n\r\n```c++\r\n// example3_2\r\n\r\nstd::list\u003cint\u003e list;\r\nlist.push_back(100);\r\nlist.push_back(200);\r\nlist.push_back(300);\r\n\r\nbool result1 = Json::equal(list, \"[ 100, 200, 300 ]\");  // true\r\n\r\nbool result2 = Json::equal(list, \"[ 300, 100, 200 ]\");  // true\r\n\r\nbool result3 = Json::equal(list, \"[ 300, 100, 200 ]\", false);  // false\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichishino%2Fjsonity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fichishino%2Fjsonity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichishino%2Fjsonity/lists"}