{"id":26059959,"url":"https://github.com/mysticastra/jsoncraftor","last_synced_at":"2026-05-09T16:50:19.930Z","repository":{"id":280089462,"uuid":"940895296","full_name":"mysticastra/JsonCraftor","owner":"mysticastra","description":"JsonCraftor is a lightweight, header-only JSON parser for C that maps JSON data directly to C structs. It provides type-safe parsing with support for nested objects and arrays.","archived":false,"fork":false,"pushed_at":"2025-03-22T07:56:03.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-22T08:27:32.154Z","etag":null,"topics":["c","json","parser"],"latest_commit_sha":null,"homepage":"","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/mysticastra.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-03-01T02:21:19.000Z","updated_at":"2025-03-22T07:56:30.000Z","dependencies_parsed_at":"2025-03-01T07:29:43.083Z","dependency_job_id":null,"html_url":"https://github.com/mysticastra/JsonCraftor","commit_stats":null,"previous_names":["mysticastra/jsoncraftor"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mysticastra/JsonCraftor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticastra%2FJsonCraftor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticastra%2FJsonCraftor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticastra%2FJsonCraftor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticastra%2FJsonCraftor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mysticastra","download_url":"https://codeload.github.com/mysticastra/JsonCraftor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysticastra%2FJsonCraftor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278308623,"owners_count":25965654,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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","parser"],"created_at":"2025-03-08T13:48:46.406Z","updated_at":"2025-10-04T11:56:38.351Z","avatar_url":"https://github.com/mysticastra.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonCraftor\n\nJsonCraftor is a lightweight, header-only JSON parser for C that maps JSON data directly to C structs. It provides type-safe parsing with support for nested objects and arrays.\n\n## Features\n\n- **Header-only**: Just include `jsoncraftor.h` in your project\n- **Type-safe parsing**: Automatic type checking and conversion\n- **Struct mapping**: Direct mapping of JSON to C structs\n- **Nested objects**: Support for complex nested structures\n- **Array support**: Handle both primitive and string arrays\n- **Required fields**: Mark fields as required or optional\n- **Error handling**: Detailed error messages for parsing failures\n- **No external dependencies**: Only uses standard C libraries\n\n## Supported Types\n\n- `int`: Integer values\n- `double`: Floating-point values\n- `bool`: Boolean values (true/false)\n- `char[]`: String values\n- `struct`: Nested objects\n- Arrays of:\n  - Integers\n  - Strings\n\n## Usage\n\n1. Include the header:\n```c\n#include \"jsoncraftor.h\"\n```\n\n2. Define your structs:\n```c\ntypedef struct {\n    char street[100];\n    int number;\n    char city[50];\n} Address;\n\ntypedef struct {\n    int age;\n    char name[50];\n    bool is_student;\n    double gpa;\n    Address address;        // Nested object\n    int scores[5];         // Array of integers\n    char tags[3][20];      // Array of strings\n} Person;\n```\n\n3. Create JSON mappings:\n```c\n// For nested objects\nJsonMap address_mappings[] = {\n    {\"street\", \u0026addr.street, 's', sizeof(addr.street), true, NULL},\n    {\"number\", \u0026addr.number, 'i', 0, true, NULL},\n    {\"city\", \u0026addr.city, 's', sizeof(addr.city), false, NULL}\n};\n\n// For arrays\nJsonMap score_item = {\"item\", NULL, 'i', 0, true, NULL};\nJsonMap tag_item = {\"item\", NULL, 's', 20, false, NULL};\n\n// Main mappings\nJsonMap mappings[] = {\n    {\"age\", \u0026person.age, 'i', 0, true, NULL},\n    {\"name\", \u0026person.name, 's', sizeof(person.name), true, NULL},\n    {\"is_student\", \u0026person.is_student, 'b', 0, false, NULL},\n    {\"gpa\", \u0026person.gpa, 'd', 0, false, NULL},\n    {\"address\", \u0026person.address, 'o', 3, true, address_mappings},\n    {\"scores\", person.scores, 'a', 5, true, \u0026score_item},\n    {\"tags\", person.tags, 'a', 3, false, \u0026tag_item}\n};\n```\n\n4. Parse JSON:\n```c\nchar* error = NULL;\nif (parse_json(json_string, mappings, mapping_count, \u0026error)) {\n    // Success: use your populated struct\n} else {\n    printf(\"Error: %s\\n\", error);\n}\n```\n\n## JsonMap Structure\n\n```c\ntypedef struct JsonMap {\n    const char* json_key;     // JSON key name\n    void* struct_member;      // Pointer to struct member\n    char type;               // Type identifier\n    size_t size;            // Size for strings/arrays\n    bool required;          // Whether field is required\n    struct JsonMap* nested; // For nested objects/arrays\n} JsonMap;\n```\n\n### Type Identifiers\n\n- `'i'`: Integer\n- `'s'`: String\n- `'b'`: Boolean\n- `'d'`: Double\n- `'o'`: Object\n- `'a'`: Array\n\n## Building and Testing\n\nThe project uses a Makefile with the following targets:\n\n```bash\nmake all          # Build everything\nmake example      # Build the example\nmake test         # Run tests\nmake clean        # Clean build files\nmake help         # Show help\n```\n\n### Running Tests\n\n```bash\nmake test\n```\n\n### Running Example\n\n```bash\nmake run\n```\n\n## Example Output\n\n```bash\nPerson parsed successfully!\nName: John\nAge: 25\nIs student: yes\nGPA: 3.80\nAddress: Main St 123, New York\nScores: [85, 92, 88, 95, 90]\nTags: [\"smart\", \"friendly\", \"active\"]\n```\n\n## Error Handling\n\nThe parser provides detailed error messages for various scenarios:\n\n- Missing required fields\n- Invalid value types\n- Array size mismatches\n- Invalid JSON syntax\n- Unterminated strings\n- Nested object errors\n\n## Project Structure\n\n```\nJsonCraftor/\n├── jsoncraftor.h        # Main parser header\n├── examples/            # Example usage\n│   └── example.c       # Example program\n├── tests/              # Test suite\n│   └── test_parser.c   # Parser tests\n└── Makefile            # Build system\n```\n\n## Contributing\n\nFeel free to submit issues, fork the repository, and create pull requests for any improvements.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysticastra%2Fjsoncraftor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmysticastra%2Fjsoncraftor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysticastra%2Fjsoncraftor/lists"}