{"id":21833625,"url":"https://github.com/gflegar/json-printer","last_synced_at":"2026-05-16T13:36:19.122Z","repository":{"id":93408923,"uuid":"125518112","full_name":"gflegar/json-printer","owner":"gflegar","description":"KISS header-only library for printing JSON objects to C++ streams.","archived":false,"fork":false,"pushed_at":"2018-05-20T12:28:34.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-26T09:29:02.489Z","etag":null,"topics":["json"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gflegar.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":"2018-03-16T13:11:29.000Z","updated_at":"2018-05-20T10:26:14.000Z","dependencies_parsed_at":"2023-06-27T01:43:02.312Z","dependency_job_id":null,"html_url":"https://github.com/gflegar/json-printer","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/gflegar%2Fjson-printer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gflegar%2Fjson-printer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gflegar%2Fjson-printer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gflegar%2Fjson-printer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gflegar","download_url":"https://codeload.github.com/gflegar/json-printer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244807641,"owners_count":20513678,"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"],"created_at":"2024-11-27T19:32:28.254Z","updated_at":"2026-05-16T13:36:14.103Z","avatar_url":"https://github.com/gflegar.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSON printer\n============\n\n[![pipeline status](https://gitlab.com/gflegar/json-printer-ci/badges/master/pipeline.svg)](https://gitlab.com/gflegar/json-printer-ci/commits/master)\n\nJSON printer is a header-only C++11 library for printing JSON objects to C++\nstreams.\nIt tries to follow the KISS principle, so the entire library consists of 1\nclass with 2 methods implemented in roughly ~150 lines of code.\n\nInstallation\n------------\n\nJust copy `json_printer.hpp` somewhere in you include path (e.g. you program's\ndirectory).\n\nDocumentation\n-------------\n\nThe [example](example.cpp) covers all the features in the library:\n\n```c++\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n\n\n#include \"json_printer.hpp\"\n\n\nint main()\n{\n    using json_printer = jpr::json_printer;\n    const auto pretty_print = true;  // trade output size for readability\n    const auto indent = 2;           // indentation level when pretty-printing\n    json_printer out(std::cout, pretty_print, indent);\n\n    out.print(\"Tesla\", json_printer::array);\n        out.print(json_printer::object);  // inside array, pass just the value\n            out.print(\"name\", \"K20\");     // inside object, pass name \u0026 value\n            // out.print(\"K20\");          // error: need name inside of object\n            out.print(\"cores\", 2496);\n        out.finalize();\n        // out.print(\"name\", \"value\");    // error: can't have name in array\n    // json_printer also supports chaining\n        out.print(json_printer::object)\n            .print(\"name\", \"K40\")\n            .print(\"cores\", 2880)\n        .finalize()\n        .print(json_printer::object)\n            .print(\"name\", \"K80\")\n            .print(\"cores\", 4992)\n        .finalize()\n        .print(json_printer::object)\n            .print(\"name\", \"P100\")\n            .print(\"cores\", 3584)\n        .finalize()\n        .print(json_printer::object)\n            .print(\"name\", \"V100\")\n            .print(\"cores\", 5120)\n        .finalize()\n    .finalize();\n\n    // let's just list a couple of GeForces\n    out.print(\"GeForce\", json_printer::array);\n    for (auto num : {960, 970, 980, 1050, 1060, 1070, 1080}) {\n        out.print(std::string(\"GTX\") + std::to_string(num));\n    }\n    out.finalize();\n\n    // and forget all about Quadros\n    out.print(\"Quadro\", nullptr);\n}\n```\n\n### Output\n\n```json\n{\n  \"Tesla\" : [\n    {\n      \"name\" : \"K20\",\n      \"cores\" : 2496\n    },\n    {\n      \"name\" : \"K40\",\n      \"cores\" : 2880\n    },\n    {\n      \"name\" : \"K80\",\n      \"cores\" : 4992\n    },\n    {\n      \"name\" : \"P100\",\n      \"cores\" : 3584\n    },\n    {\n      \"name\" : \"V100\",\n      \"cores\" : 5120\n    }\n  ],\n  \"GeForce\" : [\n    \"GTX960\",\n    \"GTX970\",\n    \"GTX980\",\n    \"GTX1050\",\n    \"GTX1060\",\n    \"GTX1070\",\n    \"GTX1080\"\n  ],\n  \"Quadro\" : null\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgflegar%2Fjson-printer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgflegar%2Fjson-printer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgflegar%2Fjson-printer/lists"}