{"id":13730390,"url":"https://github.com/ymglez/jsonpack","last_synced_at":"2025-05-08T03:30:39.178Z","repository":{"id":73640615,"uuid":"42066158","full_name":"ymglez/jsonpack","owner":"ymglez","description":"JsonPack is a high-performance and extremely easy-to-use JSON serialization library","archived":false,"fork":false,"pushed_at":"2016-01-22T12:43:22.000Z","size":13553,"stargazers_count":39,"open_issues_count":0,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-04T02:09:32.088Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ymglez.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}},"created_at":"2015-09-07T17:31:39.000Z","updated_at":"2022-02-21T22:13:13.000Z","dependencies_parsed_at":"2023-04-18T19:08:14.537Z","dependency_job_id":null,"html_url":"https://github.com/ymglez/jsonpack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymglez%2Fjsonpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymglez%2Fjsonpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymglez%2Fjsonpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ymglez%2Fjsonpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ymglez","download_url":"https://codeload.github.com/ymglez/jsonpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224695486,"owners_count":17354420,"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":[],"created_at":"2024-08-03T02:01:14.181Z","updated_at":"2024-11-14T21:30:56.886Z","avatar_url":"https://github.com/ymglez.png","language":"C++","readme":"#JsonPack\r\n\r\n## Overview\r\n\r\nJsonPack is a high-performance and extremely easy-to-use JSON serialization\r\nlibrary for C++ 11, it provide a absolute abstraction layer of this Data Interchange Format. From now on,\r\nyou only should take care about managing your C++ objects and JsonPack will make the rest.\r\n\r\n## Features\r\n\r\n* Easy-to-use, contains a very short and intuitive API. See Example section\r\n\r\n* Very fast: template metaprograming, zero string copy and fast number conversions.\r\n\r\n* Support serialization/deserialization for c++ types:\r\n  bool, char, int, unsigned int, long, unsigned long,\r\n  long long,unsigned long long, float, double and std::string.\r\n  \r\n* Support serialization/deserialization for c++ standard containers:\r\n  array, vector, deque, list, forward_list, set, multiset, unordered_set, unordered_multiset.\r\n  \r\n* Support serialization/deserialization for c++ standard associative containers:\r\n  map, multimap, unordered_map and unordered_multimap with std::string key \r\n* Parsing error management.\r\n\r\n* JSON keys match with C++ identifiers name convention when json blob read directly\r\n  into the data object.\r\n\r\n* DOM style parsing with nice data recovering.\r\n\r\n## Example\r\n\r\n```cpp\r\n#include \u003cjsonpack.hpp\u003e\r\n\r\nstruct  DataObject\r\n{\r\n\tDataObject():\r\n        mInt(362880),\r\n        mFloat(3.1415926535897932384626433832795f),\r\n        mCad(\"This, \\\" is a \\\", \\'test\"),\r\n\t\tisObject(true),\r\n        caracter('$'),\r\n        degrees({{\"Washington\", {12.5, 15.2}},{\"Havana\", {25.3, 23.4}},{\"Singapour\", {6.0}}})\r\n\t{}\r\n\r\n\tint mInt;\r\n\tfloat mFloat;\r\n\tstd::string mCad;\r\n\tbool isObject;\r\n\tchar caracter;\r\n    std::map\u003cstd::string, std::vector\u003cfloat\u003e\u003e degrees ;\r\n\r\n\t// The defined members, will be the JSON attributes set\r\n\t// Pairs \u003c\"key\" : value\u003e, are: \u003c\"member-name\" : member-value \u003e\r\n    DEFINE_JSON_ATTRIBUTES(mFloat, mInt, mCad, isObject, caracter, degrees)\r\n};\r\n\r\nint main()\r\n{\r\n\t// manage my object\r\n    DataObject src, out;\r\n\r\n\t//serialize object\r\n    //pretty print\r\n    //param bool pretty     if or not output will be pretty-printed\r\n    //param unsigned indent degree of indentation(spaces)\r\n    char* serialized = src.json_pack(true, 2);\r\n    printf(\"pretty json: \\n%s\\n\", serialized);\r\n\t\r\n\t//deserialize json\r\n\ttry\r\n\t{\r\n\t\tout.json_unpack(serialized, strlen(serialized) );\r\n        printf(\"\\ndeserialized object:\\n %s\\n\", out.json_pack());\r\n    }\r\n\tcatch (jsonpack::jsonpack_error \u0026e)\r\n\t{\r\n\t\tprintf(\"error: %s\\n\", e.what());\r\n\t}\r\n\r\n\tfree(serialized);\r\n\tgetchar();\r\n\treturn 0;\r\n}\r\n```\r\n## DOM Style example\r\n```cpp\r\n#include \u003cjsonpack.hpp\u003e\r\n\r\nstruct  DataObject\r\n{\r\n\tDataObject():\r\n\t\tmInt(0),\r\n\t\tmFloat(0.0),\r\n\t\tmCad(\"\"),\r\n\t\tisObject(true),\r\n\t\tcaracter(0)\r\n\t{}\r\n\r\n\tint mInt;\r\n\tfloat mFloat;\r\n\tstd::string mCad;\r\n\tbool isObject;\r\n\tchar caracter;\r\n};\r\n\r\nint main()\r\n{\r\n    DataObject out;\r\n\r\n\tstd::string json_obj = \"{\\\"mFloat\\\":3.1415926535897932384626433832795,\\\"mInt\\\":362880,\\\"mCad\\\":\\\"This, \\\\\\\" is a 'test\\\",\\\"isObject\\\":true,\\\"caracter\\\":\\\"$\\\"}\";\r\n\r\n    std::string json_arr = \"[45.254, 487.000025255, 0.658]\";\r\n    \r\n    try\r\n    {\r\n\t\t//DOM style parse json object\r\n        jsonpack::value obj;\r\n\r\n        obj.json_unpack(json_obj.c_str(), json_obj.length() );\r\n\t\t\r\n        // Explicit type conversion: two ways\r\n\r\n//        obj[\"mFloat\"](out.mFloat);\r\n        out.mFloat = obj[\"mFloat\"].get\u003cfloat\u003e();\r\n\r\n//        obj[\"mInt\"](out.mInt);\r\n        out.mInt = obj[\"mInt\"].get\u003cint\u003e();\r\n\r\n//        document_obj[\"mCad\"](out.mCad);\r\n        out.mCad = obj[\"mCad\"].get\u003cstd::string\u003e();\r\n\r\n//        obj[\"isObject\"](out.isObject);\r\n        out.isObject = obj[\"isObject\"].get\u003cbool\u003e();\r\n\r\n//        obj[\"caracter\"](out.caracter);\r\n        out.caracter = obj[\"caracter\"].get\u003cchar\u003e();\r\n\r\n\t\tprintf(\"\\nresult: \\nout.mFloat=%0.16f\\nout.mInt=%d\\nout.mCad=%s\\nout.isObject=%d\\nout.caracter=%c\\n\",\r\n              out.mFloat, out.mInt, out.mCad.data(), out.isObject, out.caracter );\r\n\r\n\t\t//DOM style parse json array\r\n        jsonpack::value list;\r\n\r\n        list.json_unpack(json_arr.c_str(), json_arr.length() );\r\n\r\n        //can be: array, deque, list, forward_list, set, multiset, unordered_set and unordered_multiset.\r\n//        std::vector\u003cdouble\u003e real_list;\r\n//        list(real_list);\r\n        auto real_list = list.get\u003cstd::vector\u003cdouble\u003e\u003e();\r\n\r\n        for(auto v : real_list)\r\n            printf(\"%f \", v);\r\n\r\n\t\tprintf(\"\\n\");\r\n\r\n    }\r\n    catch (jsonpack::jsonpack_error \u0026e)\r\n    {\r\n        printf(\"error: %s\\n\", e.what());\r\n    }\r\n\t\r\n    getchar();\r\n\r\n    return 0;\r\n}\r\n```\r\n## Build\r\n\r\n### You will need:\r\n\r\n- cmake \u003e= 2.8.0\r\n- gcc \u003e= 4.7 OR msvc \u003e= 11 OR clang \u003e= 2.9\r\n\r\n### Using terminal\r\n\r\n* Without example:\r\n\r\n  ```bash\r\n  $ cd jsonpack\r\n  $ mkdir build\r\n  $ cd build\r\n  $ cmake .. -DCMAKE_BUILD_TYPE=Release\r\n  $ make\r\n  $ sudo make install\r\n  ```\r\n\r\n* With example:\r\n\r\n  ```bash\r\n  $ cd jsonpack\r\n  $ mkdir build\r\n  $ cd build\r\n  $ cmake ..  -DJSONPACK_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release\r\n  $ make\r\n  $ sudo make install\r\n  ```\r\n\r\n\r\n### GUI on Windows\r\n\r\n1. Launch cmake GUI client\r\n\r\n2. Set 'Where is the source code:' text box and 'Where to build the binaries:' text box.\r\n\r\n3. Click 'Configure' button.\r\n\r\n4. Choose your Visual Studio version.\r\n\r\n5. Click 'Generate' button.\r\n\r\n6. Open the created jsonpack.sln on Visual Studio.\r\n\r\n7. Build all\r\n\r\n## Contributing\r\n\r\n1. Fork it!\r\n2. Create your feature branch: git checkout -b my-new-feature\r\n3. Commit your changes: git commit -am 'Add some feature'\r\n4. Push to the branch: git push origin my-new-feature\r\n5. Submit a pull request :D\r\n\r\n## License\r\n----------\r\n\r\nJsonpack is licensed under the Apache License Version 2.0. See\r\nthe [`LICENSE`](./LICENSE) file for details.\r\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymglez%2Fjsonpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fymglez%2Fjsonpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fymglez%2Fjsonpack/lists"}