{"id":19436417,"url":"https://github.com/beached/json_to_cpp","last_synced_at":"2025-04-24T21:31:14.379Z","repository":{"id":44362953,"uuid":"74433639","full_name":"beached/json_to_cpp","owner":"beached","description":"Generate C++ class from JSON data","archived":false,"fork":false,"pushed_at":"2023-03-30T03:22:37.000Z","size":187,"stargazers_count":47,"open_issues_count":2,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-03T11:44:20.774Z","etag":null,"topics":["cpp","json","serialization"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beached.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":"2016-11-22T04:16:03.000Z","updated_at":"2024-09-15T09:38:00.000Z","dependencies_parsed_at":"2024-11-10T15:11:37.517Z","dependency_job_id":"ddc2d1d8-3501-43f5-a296-e1c8b1b57a35","html_url":"https://github.com/beached/json_to_cpp","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fjson_to_cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fjson_to_cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fjson_to_cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beached%2Fjson_to_cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beached","download_url":"https://codeload.github.com/beached/json_to_cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250712912,"owners_count":21475102,"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","json","serialization"],"created_at":"2024-11-10T15:11:02.646Z","updated_at":"2025-04-24T21:31:14.116Z","avatar_url":"https://github.com/beached.png","language":"C++","readme":"# JSON to C++\n\nThis program will take either a json file or a URL to a web service and build C++ classes to work with that data. By\ndefault, it will create the serialization linkage for the JsonLink library that is part\nof https://github.com/beached/daw_json_link .\n\n* std::optional is used for optional members(those that are not always there or are null in some cases\n* std::string is used for strings\n* int64_t is used for integral types\n* double is used for real types\n* bool is used for boolean types\n* classes are given the name of their member suffixed with a \"_t\"\n* identifier names are filtered such that C++ keywords, empty id's, or all number id's are prefixed with _json\n* Any character in an id that isn't A-Za-z0-9 or _ will be escaped via 0xXXX\n* Autogenerated types are their member name suffixed with a _t.\n\n# Running\n\nTo output the C++ code to the terminal one just needs to type ```json_to_cpp_bin --in_file jsonfile.json``` or for a url\nsomething like ```json_to_cpp_bin --in_file http://ip.jsontest.com/```\n\n```  \nCommand line options\nOptions:\n  --help                                print option descriptions\n  --in_file arg                         json source file path or url\n  --kv_paths arg                        Specify class members that are key \n                                        value pairs\n  --use_jsonlink arg (=1)               Use JsonLink serializaion/deserializati\n                                        on\n  --has_cpp20 arg (=0)                  Enables use of non-type class template \n                                        arguments\n  --output_file arg                     output goes to c++ header file.\n  --allow_overwrite arg (=0)            Overwrite existing output files\n  --hide_null_only arg (=1)             Do not output json entries that are \n                                        only ever null\n  --use_string_view arg (=0)            Use std::string_view instead of \n                                        std::string.  Must ensure buffer is \n                                        available after parsing when this is \n                                        used\n  --root_object arg (=root_object)      Name of the nameless root object\n  --user_agent arg (=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.100 Safari/537.36)\n                                        User agent to use when downloading via \n                                        URL\n```\n\n# Example\n\n## H2 JSON Data\n\n```\n{\n    \"glossary\": {\n        \"title\": \"example glossary\",\n        \"GlossDiv\": {\n            \"title\": \"S\",\n            \"GlossList\": {\n                \"GlossEntry\": {\n                    \"ID\": \"SGML\",\n                    \"SortAs\": \"SGML\",\n                    \"GlossTerm\": \"Standard Generalized Markup Language\",\n                    \"Acronym\": \"SGML\",\n                    \"Abbrev\": \"ISO 8879:1986\",\n                    \"GlossDef\": {\n                        \"para\": \"A meta-markup language, used to create markup languages such as DocBook.\",\n                        \"GlossSeeAlso\": [\"GML\", \"XML\"]\n                    },  \n                    \"GlossSee\": \"markup\"\n                }   \n            }   \n        }   \n    }   \n}\n```\n\n## Generated C++ Code by calling ```json_to_cpp --in_file name.json```\n\n```c++\n#include \u003cdaw/json/daw_json_link.h\u003e\n#include \u003cstring\u003e\n#include \u003ctuple\u003e\n#include \u003cvector\u003e\n\nstruct GlossDef_t {\n  std::string para;\n  std::vector\u003cstd::string\u003e GlossSeeAlso;\n}; // GlossDef_t\n\nstruct GlossEntry_t {\n  std::string ID;\n  std::string SortAs;\n  std::string GlossTerm;\n  std::string Acronym;\n  std::string Abbrev;\n  GlossDef_t GlossDef;\n  std::string GlossSee;\n}; // GlossEntry_t\n\nstruct GlossList_t {\n  GlossEntry_t GlossEntry;\n}; // GlossList_t\n\nstruct GlossDiv_t {\n  std::string title;\n  GlossList_t GlossList;\n}; // GlossDiv_t\n\nstruct glossary_t {\n  std::string title;\n  GlossDiv_t GlossDiv;\n}; // glossary_t\n\nstruct root_object_t {\n  glossary_t glossary;\n}; // root_object_t\n\nnamespace daw::json {\n  template\u003c\u003e\n  struct json_data_contract\u003cGlossDef_t\u003e {\n    static constexpr char const mem_para[] = \"para\";\n    static constexpr char const mem_GlossSeeAlso[] = \"GlossSeeAlso\";\n    using type = json_member_list\u003c\n      json_string\u003cmem_para\u003e,\n      json_array\u003cmem_GlossSeeAlso, std::string, std::vector\u003cstd::string\u003e\u003e\u003e;\n\n    static inline auto to_json_data( GlossDef_t const \u0026value ) {\n      return std::forward_as_tuple( value.para, value.GlossSeeAlso );\n    }\n  };\n} \nnamespace daw::json {\n  template\u003c\u003e\n  struct json_data_contract\u003cGlossEntry_t\u003e {\n    static constexpr char const mem_ID[] = \"ID\";\n    static constexpr char const mem_SortAs[] = \"SortAs\";\n    static constexpr char const mem_GlossTerm[] = \"GlossTerm\";\n    static constexpr char const mem_Acronym[] = \"Acronym\";\n    static constexpr char const mem_Abbrev[] = \"Abbrev\";\n    static constexpr char const mem_GlossDef[] = \"GlossDef\";\n    static constexpr char const mem_GlossSee[] = \"GlossSee\";\n    using type = json_member_list\u003c\n      json_string\u003cmem_ID\u003e, json_string\u003cmem_SortAs\u003e, json_string\u003cmem_GlossTerm\u003e,\n      json_string\u003cmem_Acronym\u003e, json_string\u003cmem_Abbrev\u003e,\n      json_class\u003cmem_GlossDef, GlossDef_t\u003e, json_string\u003cmem_GlossSee\u003e\u003e;\n\n    static inline auto to_json_data( GlossEntry_t const \u0026value ) {\n      return std::forward_as_tuple( value.ID, value.SortAs, value.GlossTerm,\n                                    value.Acronym, value.Abbrev, value.GlossDef,\n                                    value.GlossSee );\n    }\n  };\n} \nnamespace daw::json {\n  template\u003c\u003e\n  struct json_data_contract\u003cGlossList_t\u003e {\n    static constexpr char const mem_GlossEntry[] = \"GlossEntry\";\n    using type = json_member_list\u003cjson_class\u003cmem_GlossEntry, GlossEntry_t\u003e\u003e;\n\n    static inline auto to_json_data( GlossList_t const \u0026value ) {\n      return std::forward_as_tuple( value.GlossEntry );\n    }\n  };\n} \nnamespace daw::json {\n  template\u003c\u003e\n  struct json_data_contract\u003cGlossDiv_t\u003e {\n    static constexpr char const mem_title[] = \"title\";\n    static constexpr char const mem_GlossList[] = \"GlossList\";\n    using type = json_member_list\u003cjson_string\u003cmem_title\u003e,\n                                  json_class\u003cmem_GlossList, GlossList_t\u003e\u003e;\n\n    static inline auto to_json_data( GlossDiv_t const \u0026value ) {\n      return std::forward_as_tuple( value.title, value.GlossList );\n    }\n  };\n} \nnamespace daw::json {\n  template\u003c\u003e\n  struct json_data_contract\u003cglossary_t\u003e {\n    static constexpr char const mem_title[] = \"title\";\n    static constexpr char const mem_GlossDiv[] = \"GlossDiv\";\n    using type = json_member_list\u003cjson_string\u003cmem_title\u003e,\n                                  json_class\u003cmem_GlossDiv, GlossDiv_t\u003e\u003e;\n\n    static inline auto to_json_data( glossary_t const \u0026value ) {\n      return std::forward_as_tuple( value.title, value.GlossDiv );\n    }\n  };\n} \nnamespace daw::json {\n  template\u003c\u003e\n  struct json_data_contract\u003croot_object_t\u003e {\n    static constexpr char const mem_glossary[] = \"glossary\";\n    using type = json_member_list\u003cjson_class\u003cmem_glossary, glossary_t\u003e\u003e;\n\n    static inline auto to_json_data( root_object_t const \u0026value ) {\n      return std::forward_as_tuple( value.glossary );\n    }\n  };\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeached%2Fjson_to_cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeached%2Fjson_to_cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeached%2Fjson_to_cpp/lists"}