{"id":46768986,"url":"https://github.com/zltl/json-gen-c","last_synced_at":"2026-03-09T22:42:58.378Z","repository":{"id":43011096,"uuid":"472672527","full_name":"zltl/json-gen-c","owner":"zltl","description":"A program to generate C code for json manipulation","archived":false,"fork":false,"pushed_at":"2025-11-23T16:05:18.000Z","size":2430,"stargazers_count":24,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-23T17:28:44.662Z","etag":null,"topics":["c","json"],"latest_commit_sha":null,"homepage":"https://zltl.github.io/json-gen-c/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zltl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-03-22T08:18:35.000Z","updated_at":"2025-11-23T16:04:59.000Z","dependencies_parsed_at":"2025-08-16T19:17:23.895Z","dependency_job_id":null,"html_url":"https://github.com/zltl/json-gen-c","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/zltl/json-gen-c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zltl%2Fjson-gen-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zltl%2Fjson-gen-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zltl%2Fjson-gen-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zltl%2Fjson-gen-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zltl","download_url":"https://codeload.github.com/zltl/json-gen-c/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zltl%2Fjson-gen-c/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30314930,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T20:05:46.299Z","status":"ssl_error","status_checked_at":"2026-03-09T19:57:04.425Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["c","json"],"created_at":"2026-03-09T22:42:58.271Z","updated_at":"2026-03-09T22:42:58.359Z","avatar_url":"https://github.com/zltl.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"json-gen-c\n---\n\n[![build test action](https://github.com/zltl/json-gen-c/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/zltl/json-gen-c/actions/workflows/test.yml)\n\n\u003e Fast, tiny, and friendly code generator that turns your C structs into fully featured JSON serializers/deserializers.\n\n## Highlights\n\n- **Schema-first workflow** – describe your structs once, generate battle-tested C code automatically.\n- **Zero runtime reflection** – everything happens at compile time, so the generated code stays fast and lean.\n- **Thread-safe runtime** – the parsing context uses explicit structures rather than globals.\n- **Batteries included** – includes a lightweight `sstr` string helper library and ready-made array helpers.\n- **CI-friendly build** – warnings are treated as errors and the Make targets work the same locally and in automation.\n\n## Contents\n\n- [Overview](#overview)\n- [Build and Install](#build-and-install)\n- [Quick Start](#quick-start)\n- [The Format of Structs Definition File](#the-format-of-structs-definition-file)\n- [The JSON API](#the-json-api)\n- [More Resources](#more-resources)\n- [Contributing \u0026 Community](#contributing--community)\n\n## Overview\n\njson-gen-c is a program for serializing C structs to JSON and\ndeserializing JSON to C structs. It parses struct definition files\nthen generates C code to handle both directions.\n\n![covor](https://raw.githubusercontent.com/zltl/json-gen-c/main/doc/json-gen-c.png)\n\n- [Document](https://zltl.github.io/json-gen-c/)\n\n## Build and Install\n\n```bash\nmake\nsudo make install\n```\n\nThe project uses a modern, efficient build system with support for parallel compilation:\n\n```bash\n# Parallel build (recommended)\nmake -j$(nproc)\n\n# Debug build\nmake debug\n\n# Build with sanitizers\nmake sanitize\n\n# Show build configuration\nmake show-config\n```\n\nTo build example, tests, and benchmarks\n\n```bash\n# build ./build/example/example\nmake example\n# build ./build/test/unit_test\nmake test\n# build ./build/benchmark/json_bench\nmake benchmark\n```\n\nAll build artifacts are organized under the `build/` directory:\n- `build/bin/` - Main executable\n- `build/lib/` - Static libraries  \n- `build/example/` - Example executable\n- `build/test/` - Test executables\n- `build/benchmark/` - Benchmark executable\n\n## Quick Start\n\n[example](./example/example.json-gen-c)\n\n### Define Structs\n\nFor example, create a file name `struct.json-gen-c` as contents below:\n\n```C\nstruct A {\n    int int_val1;\n    int int_val2;\n    long long_val;\n    double double_val;\n    float float_val;\n    sstr_t sstr_val;\n    int int_val_array[];\n    B b_val;\n};\n\nstruct B {\n    int id;\n};\n```\n\nNote that we don't use C-style string `char*`, a more resonable type is \n`sstr_t`. You can find more details about `sstr_t` in \n[document of sstr](https://zltl.github.io/json-gen-c/sstr_8h.html).\n\n### Compiling Your Struct Definition File\n\n```bash\njson-gen-c -in struct.json-gen-c -out .\n```\n\nThis generates the following files in your specified destination directory:\n\n- `json.gen.h`, the header which declares your generated structures\n  and functions.\n- `json.gen.c`, which contains the implementation of your functions.\n- `sstr.h`, `sstr.c`, the string manipulation helper functions that \n  generated code depends on.\n\n### Use Your Generated Codes\n\n#### To Serialize Structs to JSON\n```C\nstruct A a;\nA_init(\u0026a);\n// set values to a ...\n// ...\nsstr_t json_str = sstr_new();\njson_marshal_A(\u0026a, json_str);\n\nprintf(\"marshal a to json\u003e %s\\n\", sstr_cstr(json_str));\n\nsstr_free(json_str);\nA_clear(\u0026a);\n```\n\n#### To Serialize Array of Structs to JSON\n\n```C\nstruct A a[3];\nfor (i = 0; i \u003c 3; ++i) {\n    A_init(\u0026a[i]);\n    // set values to a[i] ...\n}\n\nsstr_t json_str = sstr_new();\njson_marshal_array_A(a, 3, json_str);\n\nprintf(\"marshal a[] to json\u003e %s\\n\", sstr_cstr(json_str));\n\nfor (i = 0; i \u003c 3; ++i) {\n    A_clear(\u0026a[i]);\n}\n```\n\n#### To Deserialize JSON to Structs\n```C\n// const char *p_str = \"{this is a json string}\";\n// sstr_t json_str = sstr(pstr);\n\nstruct A a;\nA_init(\u0026a);\njson_unmarshal_A(json_str, \u0026a); // json_str is a type of sstr_t\n// ...\nA_clear(\u0026a);\n```\n\n#### To Deserialize JSON to Array of Structs\n\n```C\n// const char *p_str = \"[this is a json string]\";\n// sstr_t json_str = sstr(pstr);\n\nstruct A *a = NULL;\nint len = 0;\njson_unmarshal_array_A(\u0026a, \u0026len, json_str);\n// ...\nint i;\nfor (i = 0; i \u003c len; ++i) {\n    A_clear(\u0026a[i]);\n}\nfree(a);\n```\n\n## Build System\n\nFor detailed build system documentation, see [BUILD_SYSTEM.md](BUILD_SYSTEM.md).\nIf you are new to the project, the friendly walkthrough in [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md) covers installation, schema authoring, and integration.\n\n## The Format of Structs Definition File\n\nDefine a struct like:\n\n```\nstruct \u003cstruct_name\u003e {\n    \u003cfield_type\u003e \u003cfield_name\u003e []?;\n    \u003cfield_type\u003e \u003cfield_name\u003e []?;\n    ...\n};\n```\n\nThe field type can be one of the following:\n\n- `int`\n- `long`\n- `float`\n- `double`\n- `sstr_t`\n- `bool`\n- a struct name\n\nIf a field is an array, just append `[]` after the field name.\n\n## The JSON API\n\n```C\n// initialize a struct\n// always return 0\nint \u003cstruct_name\u003e_init(struct \u003cstruct_name\u003e *obj);\n\n// uninitialize a struct\n// always return 0\nint \u003cstruct_name\u003e_clear(struct \u003cstruct_name\u003e *obj);\n\n// marshal a struct to json string.\n// return 0 if success.\nint json_marshal_\u003cstruct_name\u003e(struct \u003cstruct_name\u003e*obj, sstr_t out);\n\n// marshal an array of struct to json string.\n// return 0 if success.\nint json_marshal_array_\u003cstruct_name\u003e(struct \u003cstruct_name\u003e*obj, int len, sstr_t out);\n\n// unmarshal a json string to a struct.\n// return 0 if success.\nint json_unmarshal_\u003cstruct_name\u003e(sstr_t in, struct \u003cstruct_name\u003e*obj);\n\n// unmarshal a json string to array of struct\n// return 0 if success.\nint json_unmarshal_\u003cstruct_name\u003e(sstr_t in, struct \u003cstruct_name\u003e**obj, int *len);\n```\n\n## More Resources\n\n- [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md) – step-by-step tutorial with code snippets.\n- [example/](example/) – real schemas plus sample host programs.\n- [Online reference](https://zltl.github.io/json-gen-c/) – API documentation generated via Doxygen.\n- [doc/json-gen-c.1](doc/json-gen-c.1) – manual page installed with the CLI.\n\n## Contributing \u0026 Community\n\nWe welcome issues, ideas, documentation updates, and code contributions.\n\n- Read the [CONTRIBUTING.md](CONTRIBUTING.md) guide for local setup, coding style, and pull-request tips.\n- File bugs or feature requests via [GitHub Issues](https://github.com/zltl/json-gen-c/issues) with clear reproduction details.\n- Share what you build! Open a discussion or PR if you want your project added to a future showcase section.\n\nThanks for helping json-gen-c grow. Happy hacking!\n\n## License\n\nCodes of `json-gen-c` are licensed under GPL-3.0, except for the codes it\ngenerated. The copy right of the codes generated by `json-gen-c` is owned\nby the user who wrote the struct definition file, same as the copy right of\na PDF file generated by Latex is owned by the user who wrote the tex file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzltl%2Fjson-gen-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzltl%2Fjson-gen-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzltl%2Fjson-gen-c/lists"}