{"id":29091258,"url":"https://github.com/nodeluna/ljson","last_synced_at":"2026-04-24T20:31:43.574Z","repository":{"id":289918861,"uuid":"972829787","full_name":"nodeluna/ljson","owner":"nodeluna","description":"an easy to use header only JSON library for C++20","archived":false,"fork":false,"pushed_at":"2025-07-06T10:20:45.000Z","size":95,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-06T10:35:27.417Z","etag":null,"topics":["cpp","cpp20","cpp20-lib","cpp20-library","cpp20-modules","cppmodules","header-only","header-only-library","json","json-library"],"latest_commit_sha":null,"homepage":"https://nodeluna.github.io/ljson/","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/nodeluna.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"ko_fi":"nodeluna"}},"created_at":"2025-04-25T18:27:00.000Z","updated_at":"2025-07-06T10:20:48.000Z","dependencies_parsed_at":"2025-04-25T19:25:14.777Z","dependency_job_id":"b75d17e4-5dbc-44ca-b23a-1542f35d4f86","html_url":"https://github.com/nodeluna/ljson","commit_stats":null,"previous_names":["nodeluna/ljson"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nodeluna/ljson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeluna%2Fljson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeluna%2Fljson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeluna%2Fljson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeluna%2Fljson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodeluna","download_url":"https://codeload.github.com/nodeluna/ljson/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeluna%2Fljson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32239484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cpp","cpp20","cpp20-lib","cpp20-library","cpp20-modules","cppmodules","header-only","header-only-library","json","json-library"],"created_at":"2025-06-28T06:06:28.244Z","updated_at":"2026-04-24T20:31:43.568Z","avatar_url":"https://github.com/nodeluna.png","language":"C++","funding_links":["https://ko-fi.com/nodeluna"],"categories":[],"sub_categories":[],"readme":"ljson is an easy to use header only json library for c++\n\n# requirements\n- compiler that supports c++20\n- gcc 13 or clang 17\n\n# usage\n\n## header-only\n\n- clone the repo\n- add the include/ directory to your build system\n- include \u003cljson.hpp\u003e\n\n## c++20 modules\n\n- clone the repo\n- add the mod/ and include/ directory to your build system\n- import ljson;\n\ncheck out the example at test/import_ljson/ to see how to use the library as a module in cmake\n\n# tutorial\n\n### reading and writing to files\n```cpp\n#include \u003cljson.hpp\u003e\n#include \u003cexception\u003e\n\nint main() {\n\tstd::filesystem::path path_to_file = \"meow\";\n\n\ttry {\n\t\tljson::node node = ljson::parser::parse(path_to_file);\n\t\tstd::pair\u003cchar, int\u003e indent_config = {'\\t', 2}; // you can specifiy tab/space here and it's count\n\t\tnode.dump_to_stdout(indent_config);\n\t\tnode.dump_to_stdout(); // not specifiying defaults to {' ', 4}\n\t\tnode.dump_to_file(\"new_file.json\" /*, indent_config */);\n\n\n\t} catch (const ljson::error\u0026 error) {\n\t\t// parsing error, JSON syntax error\n\t\t// handle error\n\t}\n  \n}\n\n```\n### exception free parsing\n```cpp\n#include \u003cljson.hpp\u003e\n#include \u003cprint\u003e\n\nint main() {\n\tstd::filesystem::path path_to_file = \"meow\";\n\tljson::expected\u003cljson::node, ljson::error\u003e node = ljson::parser::try_parse(path_to_file);\n\tif (not node)\n\t{\n\t\t// handle error\n\t\tstd::println(\"{}\", node.error().message());\n\t}\n\telse\n\t{\n\t\t// parsed successfully\n\t}\n  \n}\n\n```\n\n\n### accessing and changing/setting values\n\n```cpp\n\n#include \u003cljson.hpp\u003e\n#include \u003cexception\u003e\n\nint main() {\n\tstd::filesystem::path path_to_file = \"meow\";\n\n\t// making a json object\n\tljson::node j2 = {\n\t\t {\"simple_key\", \"meow_value\"},\n\t\t {\"array_key\", ljson::node({ // ljson::node() can hold an object, array's values or a simple value\n\t\t\t\t \"arr_key1\",\n\t\t\t\t \"arr_key2\",\n\t\t\t\t \"arr_key3\",\n\t\t\t\t \"arr_key4\",\n\t\t\t\t \"arr_key5\",\n\t\t\t\t })},\n\t\t {\"object_key\", ljson::node({\n\t\t\t\t {\"obj_key1\", \"value1\"},\n\t\t\t\t {\"obj_key2\", \"value2\"},\n\t\t\t\t {\"obj_key3\", \"value3\"},\n\t\t\t\t })},\n\t};\n\n\ttry {\n\t\tljson::node node = ljson::parser::parse(path_to_file);\n\n\t\t// this function adds an object to a key\n\t\tnode.insert(\"new_object\", j2);\n\n\t\tljson::node new_node = node.at(\"object_key\").at(\"nested_key\"); // getting the value of nested_key\n\t\t\t\t\t\t\t\t\t\t\t\t // this function can throw if the key doesn't exist\n\n\t\t// to check if the key exists or not\n\t\tif (node.contains(\"object_key\")) {\n\t\t\tnew_node = node.at(\"object_key\");\n\t\t\tif (new_node.contains(\"nested_key\")) {\n\t\t\t\tnew_node = new_node.at(\"nested_key\");\n\n\t\t\t\t// to change the value, it can be done this way\n\t\t\t\tnew_node.set(\"new_value_for_nested_key\");\n\t\t\t\t// or this way\n\t\t\t\tnew_node = \"new_value_for_nested_key\";\n\t\t\t}\n\t\t}\n\n\t\t// this function adds an object to an array\n\t\tnode.at(\"object\").at(\"array_key\").push_back(j2);\n\n\t\t// this function adds a value to an array\n\t\tnode.at(\"object\").at(\"array_key\").push_back(\"new_array_value\");\n\n\t\t// to access an index inside an array pass a size_t to the .at(index) function\n\t\tnew_node = node.at(\"object\").at(\"array_key\").at(0); \n\n\t\t// to chage its value\n\t\tstd::expected\u003cstd::monostate, ljson::error\u003e ok = new_node.set(\"changed_value\");\n\t\tif (not ok) {\n\t\t\tstd::println(\"err: {}\", ok.error().message()); // ok.error().value() == ljson::error_type::wrong_type\n\t\t}\n\t\tnew_node.set(true);\n\t\tnew_node.set(12);\n\t\tnew_node.set(ljson::null); // set its value to 'null'\n\n\t\tnode.dump_to_file(\"new_file.json\"); // write the new changes\n\n\n\t} catch (const ljson::error\u0026 error) {\n\t\t// parsing error, JSON syntax error\n\t\t// handle error\n\t}\n}\n\n```\n\n\n\n### exception free key access\n\n```cpp\n\n#include \u003cljson.hpp\u003e\n#include \u003cexception\u003e\n\nint main() {\n\t// making a json object\n\tljson::node j2 = {\n\t\t {\"simple_key\", \"meow_value\"},\n\t\t {\"array_key\", ljson::node({ // ljson::node() can hold an object, array's values or a simple value\n\t\t\t\t \"arr_key1\",\n\t\t\t\t \"arr_key2\",\n\t\t\t\t \"arr_key3\",\n\t\t\t\t \"arr_key4\",\n\t\t\t\t \"arr_key5\",\n\t\t\t\t })},\n\t\t {\"object_key\", ljson::node({\n\t\t\t\t {\"obj_key1\", \"value1\"},\n\t\t\t\t {\"obj_key2\", \"value2\"},\n\t\t\t\t {\"obj_key3\", \"value3\"},\n\t\t\t\t })},\n\t};\n\n\t// this function adds an object to a key\n\tnode.insert(\"new_object\", j2);\n\n\tljson::expected\u003cstd::reference_wrapper\u003cljson::node\u003e, ljson::error\u003e simple_node = node.try_at(\"simple_key\");\n\tif (simple_node)\n\t{\n\t\tljson::node\u0026 node_ref = simple_node.value().get();\n\t\tljson::expected\u003cstd::string, ljson::error\u003e maybe_string = node_ref.try_as_string();\n\t\tif (maybe_string)\n\t\t{\n\t\t\tstd::println(\"{}\", maybe_value.value()); // prints: meow_value\n\t\t}\n\t}\n}\n\n```\n\n\n\n\n### casting to a json array and iteration\n```cpp\n#include \u003cljson.hpp\u003e\n#include \u003cexception\u003e\n\nint main() {\n\tstd::filesystem::path path_to_file = \"meow\";\n\n\ttry {\n\t\t// parse the file\n\t\tljson::node new_node = node.at(\"key\").at(\"array\");\n\t\tif (new_node.is_array()) {\n\t\t\t// this function can throw if the internal type isn't an json array\n\t\t\tstd::shared_ptr\u003cljson::array\u003e array = new_node.as_array();\n\n\t\t\tfor (ljson::node\u0026 element : *array) {\n\t\t\t\tif (element.is_value()) {\n\t\t\t\t\tstd::println(\"array element: {}, type name: {}\",\n\t\t\t\t\t\telement-\u003eas_value().stringify(), element-\u003eas_value().type_name());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\t} catch (const ljson::error\u0026 error) {\n\t\t// parsing error, JSON syntax error\n\t\t// handle error\n\t}\n  \n}\n\n```\n\n### casting to a json object and iteration\n```cpp\n#include \u003cljson.hpp\u003e\n#include \u003cexception\u003e\n\nint main() {\n\tstd::filesystem::path path_to_file = \"meow\";\n\n\ttry {\n\t\t// parse the file\n\t\tljson::node new_node = node.at(\"key\").at(\"object\");\n\t\tif (new_node.is_object()) {\n\t\t\t// this function can throw if the internal type isn't a json object\n\t\t\tstd::shared_ptr\u003cljson::object\u003e object = new_node.as_object();\n\n\t\t\tfor (auto\u0026 [key, node] : *object) {\n\t\t\t\tif (node.is_value()) {\n\t\t\t\t\tstd::println(\"object key: {} element: {}, type name: {}\", key\n\t\t\t\t\t\tnode-\u003eas_value().stringify(), node-\u003eas_value().type_name());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\n\t} catch (const ljson::error\u0026 error) {\n\t\t// parsing error, JSON syntax error\n\t\t// handle error\n\t}\n  \n}\n\n```\n\n### exception free casting\n```cpp\n#include \u003cljson.hpp\u003e\n\n// add \"try_\" in front of any casting method that throws\n\nint main()\n{\n\tljson::node node;\n\n\t// throws\n\tint number = node.as_integer();\n\tstd::string number = node.as_string();\n\n\n\t// doesn't throw\n\tljson::expected\u003cint, ljson::error\u003e number = node.try_as_integer();\n\tljson::expected\u003cstd::string, ljson::error\u003e number = node.try_as_string();\n}\n\n```\n\n\n### inserting std library containers into a node\n```cpp\n#include \u003cljson.hpp\u003e\n#include \u003cexception\u003e\n\nint main() {\n\tstd::filesystem::path path_to_file = \"meow\";\n\n\ttry {\n\t\t// parse the file\n\n\t\tstd::map\u003cstd::string, std::string\u003e object = {\n\t\t\t\t{\"meow_key\", \"value1\"},\n\t\t\t\t{\"meow_key2\", \"value2\"},\n\t\t};\n\t\tstd::list\u003cstd::string\u003e array = {\"meow\", \"meoow\"};\n\n\n\t\tif (node.is_object)\n\t\t{\n\t\t\tnode.insert(\"array\", array); // inserts an array to the value name \"array\"\n\t\t\tnode.insert(\"object\", object); // inserts an object to the value name \"object\"\n\t\t}\n\t\telse if (node.is_array())\n\t\t{\n\t\t\tnode.push_back(array); // pushes back an array at the end of the array\n\t\t\tnode.push_back(object); // pushes back an object at the end of the array\n\t\t}\n\n\t} catch (const ljson::error\u0026 error) {\n\t\t// parsing error, JSON syntax error\n\t\t// handle error\n\t}\n  \n}\n```\n\n\n# author\n\nnodeluna - nodeluna@proton.me\n\n# license\n    Copyright 2025 nodeluna\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n# special thanks to\n\n- **[tomlplusplus]** - for showing how to make a nice API\n\n[tomlplusplus]: https://github.com/marzer/tomlplusplus\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeluna%2Fljson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodeluna%2Fljson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeluna%2Fljson/lists"}