{"id":24323355,"url":"https://github.com/onepointert/jsoncpp","last_synced_at":"2026-04-15T22:33:53.657Z","repository":{"id":272820701,"uuid":"912611492","full_name":"onepointerT/jsoncpp","owner":"onepointerT","description":"A data handling and serialization library for JSON","archived":false,"fork":false,"pushed_at":"2025-01-25T10:42:18.000Z","size":1524,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-03-11T02:46:36.324Z","etag":null,"topics":["json","json-schema","serialization","serializer","text"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onepointerT.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":"2025-01-06T03:05:09.000Z","updated_at":"2025-01-25T10:42:22.000Z","dependencies_parsed_at":"2025-01-16T20:49:30.347Z","dependency_job_id":"6cc556f1-8684-4671-938e-a877d60a1ced","html_url":"https://github.com/onepointerT/jsoncpp","commit_stats":null,"previous_names":["onepointert/jsoncpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onepointerT%2Fjsoncpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onepointerT%2Fjsoncpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onepointerT%2Fjsoncpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onepointerT%2Fjsoncpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onepointerT","download_url":"https://codeload.github.com/onepointerT/jsoncpp/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242961755,"owners_count":20213315,"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":["json","json-schema","serialization","serializer","text"],"created_at":"2025-01-17T18:33:00.071Z","updated_at":"2025-10-14T03:18:13.838Z","avatar_url":"https://github.com/onepointerT.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsoncpp\n##### A data handling and serialization library for JSON\n###### v1.6.1\n\n\u003cp align=\"center\"\u003e\u003cimg width=\"100\" src=\"https://github.com/onepointerT/jsoncpp/blob/dev/doc/jsoncpp.png\" alt=\"JsonC++ logo\"\u003e\u003c/p\u003e\n\nThe library allows to read and write files in JavaScriptObjectNotation (`*.json`), to access the values and define them in a ObjectView model with commonly useful C++ operators (see examples below).\n\nIt is possible to serialize the values into the standard C/C++ types and even customly developed types or classes via inheritance.\n\n###### TODO: documentation\n\n\n#### How to use\n\n\nOne might have a `ddml.json` document such like\n\n```json\n{\n    \"ddml\": {\n        \"varname1\": {\n            \"sql\": \"SELECT * FROM table;\",\n            \"dstruct\": \"TableExampleElement\"\n        },\n        \"varname2\": {\n            \"sql\": \"SELECT * FROM table WHERE ID = 1000;\",\n            \"cacao\": \"#varname1{$sql}{\\s\\w}#varname2\",\n            \"dstruct\": \"TableExampleElement\"\n        },\n        \"varname3\": \"SELECT * FROM table WHERE wordset = varname3;\"\n    }\n}\n```\n\nand try to access it. So we have the following to do to use it with JsonC++:\n\n```c++\n#include \u003cjson.hpp\u003e\n\nusing namespace jsoncpp;\n\n// Read the document\nJson json = *JsonDocument::fromFile(\"ddml.json\");\n// Get the value ddml\nJsonObjectView\u0026 ddml = json[\"ddml\"];\n// Add a fourth variable\n// (To use the key/value-path extension you need to use `operator[]`)\nddml[\"varname4\"] \u003c\u003c new JsonObjectView( \"varname4\", \"{}\" );\nddml[\"varname4.sql\"] \u003c\u003c \"SELECT * FROM table2 WHERE wordset = varname3;\";\nddml[\"varname4.dstruct\"] \u003c\u003c \"TableExampleUserElement\";\nddml[\"varname4.serialize\"] \u003c\u003c false;\n// Or edit the first variable\nddml[\"varname1.dstruct\"] = \"TableExampleElementAll\";\nddml[\"varname1.serialize\"] \u003c\u003c true;\n// Write all changes to the file\nJsonDocument::toFile(\"ddml.json\", \u0026json);\n```\n\nIf we want to look at all changes, we might pass the `toString()` function to `std::cout`.\n\n```c++\n#include \u003ciostream\u003e\n\nstd::cout \u003c\u003c \"The current 'ddml.varname4' value is: \" \u003c\u003c ddml[\"varname4\"].toString()\n            \u003c\u003c std::endl \u003c\u003c std::endl;\n\nstd::cout \u003c\u003c \"The whole document would have the following content: \" \u003c\u003c std::endl \n            \u003c\u003c json.toString() \u003c\u003c std::endl;\n```\n\nWhich then prints the following:\n\n```console\n$\u003e The current 'ddml.varname4' value is: \"varname4\": {\n    \"sql\": \"SELECT * FROM table2 WHERE wordset = varname3;\",\n    \"dstruct\": \"TableExampleUserElement\"\n  }\n$\u003e The whole document would have the following content: \n```\n```json\n{\n    \"ddml\": {\n        \"varname1\": {\n            \"sql\": \"SELECT * FROM table;\",\n            \"dstruct\": \"TableExampleElementAll\"\n        },\n        \"varname2\": {\n            \"sql\": \"SELECT * FROM table WHERE ID = 1000;\",\n            \"cacao\": \"#varname1{$sql}{\\s\\w}#varname2\",\n            \"dstruct\": \"TableExampleElement\"\n        },\n        \"varname3\": \"SELECT * FROM table WHERE wordset = varname3;\",\n        \"varname4\": {\n            \"sql\": \"SELECT * FROM table2 WHERE wordset = varname3;\",\n            \"dstruct\": \"TableExampleUserElement\"\n        }\n    }\n}\n```\n\nThen we might want to have their values to `C++`, this is simply extensible with the in-library types or the default types of `C++`:\n\n```c++\n// Define the variables\nstd::string str1;\nbool serialize1;\ntypes::Bool json_bool;\nstd::string str3;\n\n// Put values from Json into the variables\njson[\"ddml.varname1.sql\"] \u003e\u003e str;\njson[\"ddml.varname1.serialize\"] \u003e\u003e serialize1;\njson[\"ddml.varname1.serialize\"] \u003e\u003e json_bool;\njson[\"ddml.varname3\"] \u003e\u003e str;\n\n#include \u003cjson_syntax.hpp\u003e\n\n// Do something with the values, e.g.:\nstd::list\u003c std::string_view \u003e\u0026 tokens\n    = syntax::tokenize( str, \" \" );\n\nstd::string select = tokens[0] + \" \" + tokens[1];\nstd::string from = tokens[2] + \" \" + tokens[3];\nstd::string where;\nif ( tokens.size() \u003e 4 ) {\n    size_t pos_where = str.find_first_of( \"WHERE\" );\n    if ( pos_where != str.npos )\n        where = str.substr( pos_where, str.length() - 2 );\n}\n\nif ( str1 != str3 ) {\n    sample_custom_serialize( str3 );\n    if ( serialize1 \u0026\u0026 serialize1 == json_bool ) {\n        T\u0026 custom_type = stringToType\u003cT\u003e( str1 );\n        std::cout \u003c\u003c custom_type.toString();\n        sample_custom_serialize_and_do( typeToType\u003cC, std::string\u003e(str1) );\n    }\n}\n```\n\nThat's it! Everything above is all you need to know to live and develop JavaScriptObjectNotation with the `jsoncpp` library.\n\nMore expert users may want to define their own JsonSerializable type, with can be done like below.\n\n```c++\n#include \u003cjson_serializable.hpp\u003e\n\n// This should pull in and compile all function you need\nclass SQLQuery\n    :   public types::JsonType\u003c SQLQuery, std::string \u003e\n    ,   public RefList\u003cstd::string, std::string, std::string, int, bool\u003e\n{...}\n```\n\nAll further function the compiler won't find are conversion functions, possibly:\n\n```c++\n#include \u003cjson_serializer.hpp\u003e\n\ntemplate\u003c\u003e\nSQLQuery\u0026 typeToType( const std::string\u0026 jsonstr );\ntemplate\u003c\u003e\nstd::string\u0026 typeToType( const SQLQuery\u0026 sqlq );\ntemplate\u003c\u003e\nstd::string typeToString( const SQLQuery\u0026 sqlq );\n```\n\n##### More easy own text-serializable and json-usable types\n\nA type that includes and inherits function for transformation of e.g.\n`struct YourStruct` with `YourStruct = BT` to a json-text serializable class\n`class YourJsonType` with `YourJsonType = JT` that extensible and responsibly\nenables you to serialized your struct-typed classes with `jsoncpp::types::JsonType\u003cJT, BT\u003e` to json and json strings/files.\n\nFor example inheriting a `jsoncpp::types::JsonType\u003cYourType, BaseStructedType\u003e` for your library/program could work like below.\n\n```c++\nstruct CacaoExpression {\n    std::string_view expr_str;\n};\n\nstruct ddkml_obj {\n    std::string_view var_name = \"\";\n    std::string sql = \"\";\n    CacaoExpression cacaoext;\n    std::string dstruct = \"\";\n};\n\n#include \u003cjson_types.hpp\u003e\n\nclass DdkmlObj\n    :   public jsoncpp::types::JsonType\u003c DdkmlObj, ddkml_obj \u003e\n{...}; // \u003c- Your definitions there\n```\n\nso that you need only a few functions to define to be string-transformable and usable with json:\n\n```c++\nnamespace jsoncpp {\ntemplate\u003c\u003e\nddkml::ddkml_obj\u0026 stringToType( const char* str ) {...}\ntemplate\u003c\u003e\nconst char* typeToString( const ddkml::ddkml_obj\u0026 obj ) {...}\ntemplate\u003c\u003e\nddkml::ddkml_obj\u0026 typeToType( const jsoncpp::JsonValue\u0026 json ) {...}\ntemplate\u003c\u003e\njsoncpp::JsonValue\u0026 typeToType( const ddkml::ddkml_obj\u0026 obj ) {...}\n} // namespace jsoncpp\n```\n\nAll functions you need for the inherited `JsonTextSerializableType\u003cT\u003e` and its value `T\u0026 value` are described there and above. The class `JsonType\u003cJT, BT\u003e` also needs (additional to the string-to-type functions the `typeToType\u003cBT, JsonValue\u003e` function in both transformation directions.)\n\n\n\n##### More extended JavaScriptObjectNotation Development\n\nAn extension to JSON6 in `jsoncpp` is the value's key path extension, the serializable type extension classes and functions and a more modern way to use JSON is to use key variables in value strings to look them up and shortly replace them with the real value of a json object's key/value set. Briefly one may have a `kv_ext.json`file like this\n\n```json\n{\n    \"ext\": \"key_variables\",\n    \"value_set\": {\n        \"valueA\": \"A brief excerpt of a key variable's value\",\n        \"valueB\": \"The extension #ext# will extend values with #valueA#\"\n    },\n    \"some_string\": \"This was a short demo of the vv extension namespace's extension #ext#.\n        #value_set.valueB#. Thank you for using.\"\n}\n```\n\nand with the keys-in-values extension would now use it in C++ like this\n\n```c++\n#include \u003ciostream\u003e\n#include \u003cjson_objects.hpp\u003e\n#include \u003cjson_vv.hpp\u003e\n\n// Read the `.json` file\njsoncpp::Json* json = jsoncpp::Json::fromFile(\"kv_ext.json\");\n// Write all replacings in the value \"some_string\" and print it.\nstd::cout \u003c\u003c jsoncpp::vv::variableValue(\n    json-\u003efindKeyRef( \"some_string\" ).c_str(), json, true, '#'\n) \u003c\u003c std::endl;\n// The function has the signature\n// vv::variableValue( str_value, json_values, recusive_replace, var_delim );\n```\n\nto print with the use of a complete JSON7-like document's values\n\n```console\n$\u003e This was a short demo of the vv extension namespace's extension key_variables.\n        The extension key_variables will extend values with A brief excerpt of a key variable's \n        value. Thank you for using.\n```\n\n#### License\n\nThe project is licensed under the three licenses  to be read from the upper to the last:\n\n* Academic Free License (\"AFL\") v. 3.0\n* Blue Oak Model License\n* ISC License\n\nCopyright (c) 2025 Sebastian Lau\n\n\n#### How to compile \u0026 use it\n\n```sh\n# Get the project from github\ngit clone https://github.com/onepointerT/jsoncpp.git\n# Include it now in you `CMakeLists.txt`\ninclude_directory( jsoncpp/include )\nadd_subdirectory( jsoncpp )\n...\ntarget_link_libraries( yourLib jsoncpp ... )\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonepointert%2Fjsoncpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonepointert%2Fjsoncpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonepointert%2Fjsoncpp/lists"}