{"id":18478504,"url":"https://github.com/oezeb/cpp-json","last_synced_at":"2025-05-13T18:28:17.010Z","repository":{"id":173519810,"uuid":"520520439","full_name":"oezeb/cpp-json","owner":"oezeb","description":"Simple JSON parser in C++","archived":false,"fork":false,"pushed_at":"2022-08-02T14:04:34.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T20:44:34.664Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oezeb.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-02T13:58:27.000Z","updated_at":"2022-08-02T14:02:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"159ed0d9-8ff1-4636-9280-ad41920795e4","html_url":"https://github.com/oezeb/cpp-json","commit_stats":null,"previous_names":["oezeb/cpp-json"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oezeb%2Fcpp-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oezeb%2Fcpp-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oezeb%2Fcpp-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oezeb%2Fcpp-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oezeb","download_url":"https://codeload.github.com/oezeb/cpp-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254002795,"owners_count":21997789,"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-11-06T12:10:20.966Z","updated_at":"2025-05-13T18:28:16.979Z","avatar_url":"https://github.com/oezeb.png","language":"C++","readme":"# cpp-json\n\ncpp json is a simple and lightweight JSON parser and generator for C++. \n\n## JSON Elements\n\nWe define several classes to represent JSON data. All JSON data inherits from an abstract class `json::element`.\n\n| JSON data          | C++ type                                          |\n| ------------------ | ------------------------------------------------- |\n| json::object       | std::unordered_map\\\u003cstd::string, json::element*\\\u003e |\n| json::array        | std::vector\\\u003cjson::element*\\\u003e                     |\n| json::string       | std::string                                       |\n| json::number       | double                                            |\n| json::boolean      | bool                                              |\n| json::null         | nullptr                                           |\n\n`json::element` has a method `get_value` that uses generics to return an equivalent C++ type of the JSON data.\n\n```c++\n    json::boolean b(true);\n    b.get_value\u003cbool\u003e() // true\n```\n\n## JSON Gen\n\ni.e To generate the following User JSON data:\n\n```json\n    {\n        \"name\": \"Jayden Carr\",\n        \"age\": 24,\n        \"single\": true,\n        \"phones\": [\n            \"(945)-441-6267\",\n            \"(945)-441-5532\"\n        ],\n        \"location\": {\n            \"state\": \"Hawaii\",\n            \"country\": \"United States\",\n            \"city\": \"Carlsbad\",\n            \"street\": {\n                \"name\": \"Forest Ln\",\n                \"number\": 1810\n            }\n        }\n    }\n```\n\nWe can use the following code:\n\n```c++\n    // Create a User object\n    auto user = new json::object();\n    user-\u003eset(\"name\", \"Jayden Carr\");\n    user-\u003eset(\"age\", 24);\n    user-\u003eset(\"single\", true);\n        // create an array of phones\n        auto phones = new json::array();\n        phones-\u003eadd(\"(945)-441-6267\");\n        phones-\u003eadd(\"(945)-441-5532\");\n    user-\u003eset(\"phones\", phones);\n        // create a location object\n        auto location = new json::object();\n        location-\u003eset(\"state\", \"Hawaii\");\n        location-\u003eset(\"country\", \"United States\");\n        location-\u003eset(\"city\", \"Carlsbad\");\n            // create a street object\n            auto street = new json::object();\n            street-\u003eset(\"name\", \"Forest Ln\");\n            street-\u003eset(\"number\", 1810);\n        location-\u003eset(\"street\", street);\n    user-\u003eset(\"location\", location);\n```\n\n## JSON Stringify\n\n`json::element` contains a method `to_string` that can be used to get a JSON string representation of any JSON data.\n\n```c++\nstring s = user-\u003eto_string();\n```\n\n## JSON Parse\n\nTo parse a given JSON string, we can use the `json::parse` function.\n\n```c++\n    auto e = json::parse(s); \n    // e is a json::element*\n    // Considering the above example, it can be casted to a json::object*\n    auto user = (json::object*)e;\n```\n\n## Testing\n\nCompile and run `test.cpp`\n\n    g++ test.cpp json.hpp json.cpp -o test\n\t./test\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foezeb%2Fcpp-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foezeb%2Fcpp-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foezeb%2Fcpp-json/lists"}