{"id":13440283,"url":"https://github.com/kgabis/parson","last_synced_at":"2025-05-15T14:03:19.176Z","repository":{"id":5086466,"uuid":"6248787","full_name":"kgabis/parson","owner":"kgabis","description":"Lightweight JSON library written in C.","archived":false,"fork":false,"pushed_at":"2024-05-11T14:17:50.000Z","size":382,"stargazers_count":1385,"open_issues_count":25,"forks_count":331,"subscribers_count":58,"default_branch":"master","last_synced_at":"2025-04-15T03:50:03.685Z","etag":null,"topics":["c","json","json-parser","parser"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"shichuan/javascript-patterns","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kgabis.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},"funding":{"github":["kgabis"]}},"created_at":"2012-10-16T18:02:50.000Z","updated_at":"2025-04-13T21:24:27.000Z","dependencies_parsed_at":"2023-07-06T18:46:31.765Z","dependency_job_id":"29bcbc7c-0b51-4eb6-93e8-e38a8f310682","html_url":"https://github.com/kgabis/parson","commit_stats":{"total_commits":143,"total_committers":32,"mean_commits":4.46875,"dds":"0.25874125874125875","last_synced_commit":"aad7a806672d08fbc0b5da5ec0d30e187bc584c2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fparson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fparson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fparson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgabis%2Fparson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kgabis","download_url":"https://codeload.github.com/kgabis/parson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003944,"owners_count":21196794,"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":["c","json","json-parser","parser"],"created_at":"2024-07-31T03:01:21.319Z","updated_at":"2025-04-15T03:50:08.600Z","avatar_url":"https://github.com/kgabis.png","language":"C","readme":"## About\nParson is a lightweight [json](http://json.org) library written in C.\n\n## Features\n* Lightweight (only 2 files)\n* Simple API\n* Addressing json values with dot notation (similar to C structs or objects in most OO languages, e.g. \"objectA.objectB.value\")\n* C89 compatible\n* Test suites\n\n## Installation\nRun:\n```\ngit clone https://github.com/kgabis/parson.git\n```\nand copy parson.h and parson.c to you source code tree.\n\nRun ```make test``` to compile and run tests.\n\n## Examples\n### Parsing JSON\nHere is a function, which prints basic commit info (date, sha and author) from a github repository.  \n```c\nvoid print_commits_info(const char *username, const char *repo) {\n    JSON_Value *root_value;\n    JSON_Array *commits;\n    JSON_Object *commit;\n    size_t i;\n    \n    char curl_command[512];\n    char cleanup_command[256];\n    char output_filename[] = \"commits.json\";\n    \n    /* it ain't pretty, but it's not a libcurl tutorial */\n    sprintf(curl_command, \n        \"curl -s \\\"https://api.github.com/repos/%s/%s/commits\\\" \u003e %s\",\n        username, repo, output_filename);\n    sprintf(cleanup_command, \"rm -f %s\", output_filename);\n    system(curl_command);\n    \n    /* parsing json and validating output */\n    root_value = json_parse_file(output_filename);\n    if (json_value_get_type(root_value) != JSONArray) {\n        system(cleanup_command);\n        return;\n    }\n    \n    /* getting array from root value and printing commit info */\n    commits = json_value_get_array(root_value);\n    printf(\"%-10.10s %-10.10s %s\\n\", \"Date\", \"SHA\", \"Author\");\n    for (i = 0; i \u003c json_array_get_count(commits); i++) {\n        commit = json_array_get_object(commits, i);\n        printf(\"%.10s %.10s %s\\n\",\n               json_object_dotget_string(commit, \"commit.author.date\"),\n               json_object_get_string(commit, \"sha\"),\n               json_object_dotget_string(commit, \"commit.author.name\"));\n    }\n    \n    /* cleanup code */\n    json_value_free(root_value);\n    system(cleanup_command);\n}\n\n```\nCalling ```print_commits_info(\"torvalds\", \"linux\");``` prints:  \n```\nDate       SHA        Author\n2012-10-15 dd8e8c4a2c David Rientjes\n2012-10-15 3ce9e53e78 Michal Marek\n2012-10-14 29bb4cc5e0 Randy Dunlap\n2012-10-15 325adeb55e Ralf Baechle\n2012-10-14 68687c842c Russell King\n2012-10-14 ddffeb8c4d Linus Torvalds\n...\n```\n\n### Persistence\nIn this example I'm using parson to save user information to a file and then load it and validate later.\n```c\nvoid persistence_example(void) {\n    JSON_Value *schema = json_parse_string(\"{\\\"name\\\":\\\"\\\"}\");\n    JSON_Value *user_data = json_parse_file(\"user_data.json\");\n    char buf[256];\n    const char *name = NULL;\n    if (user_data == NULL || json_validate(schema, user_data) != JSONSuccess) {\n        puts(\"Enter your name:\");\n        scanf(\"%s\", buf);\n        user_data = json_value_init_object();\n        json_object_set_string(json_object(user_data), \"name\", buf);\n        json_serialize_to_file(user_data, \"user_data.json\");\n    }\n    name = json_object_get_string(json_object(user_data), \"name\");\n    printf(\"Hello, %s.\", name);\n    json_value_free(schema);\n    json_value_free(user_data);\n    return;\n}\n```\n\n### Serialization\nCreating JSON values is very simple thanks to the dot notation. \nObject hierarchy is automatically created when addressing specific fields. \nIn the following example I create a simple JSON value containing basic information about a person.\n```c\nvoid serialization_example(void) {\n    JSON_Value *root_value = json_value_init_object();\n    JSON_Object *root_object = json_value_get_object(root_value);\n    char *serialized_string = NULL;\n    json_object_set_string(root_object, \"name\", \"John Smith\");\n    json_object_set_number(root_object, \"age\", 25);\n    json_object_dotset_string(root_object, \"address.city\", \"Cupertino\");\n    json_object_dotset_value(root_object, \"contact.emails\", json_parse_string(\"[\\\"email@example.com\\\",\\\"email2@example.com\\\"]\"));\n    serialized_string = json_serialize_to_string_pretty(root_value);\n    puts(serialized_string);\n    json_free_serialized_string(serialized_string);\n    json_value_free(root_value);\n}\n\n```\n\nOutput:\n```\n{\n    \"name\": \"John Smith\",\n    \"age\": 25,\n    \"address\": {\n        \"city\": \"Cupertino\"\n    },\n    \"contact\": {\n        \"emails\": [\n            \"email@example.com\",\n            \"email2@example.com\"\n        ]\n    }\n}\n```\n\n## Contributing\n\nI will always merge *working* bug fixes. However, if you want to add something new to the API, please create an \"issue\" on github for this first so we can discuss if it should end up in the library before you start implementing it.\nRemember to follow parson's code style and write appropriate tests.\n\n## My other projects\n* [ape](https://github.com/kgabis/ape) - simple programming language implemented in C library\n* [kgflags](https://github.com/kgabis/kgflags) - easy to use command-line flag parsing library   \n* [agnes](https://github.com/kgabis/agnes) - header-only NES emulation library\n\n## License\n[The MIT License (MIT)](http://opensource.org/licenses/mit-license.php)\n","funding_links":["https://github.com/sponsors/kgabis"],"categories":["JSON","C","Structured File Processing","结构化文件处理","进程间通信","JSON ##","Members"],"sub_categories":["JSON","Json","Graphic APIs ###"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgabis%2Fparson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkgabis%2Fparson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgabis%2Fparson/lists"}