{"id":15049454,"url":"https://github.com/lcsmuller/jsmn-find","last_synced_at":"2025-10-17T05:37:35.088Z","repository":{"id":36966377,"uuid":"446438880","full_name":"lcsmuller/jsmn-find","owner":"lcsmuller","description":"Tiny, zero-allocation JSON tokenizer written in ANSI C","archived":false,"fork":false,"pushed_at":"2025-05-07T00:56:30.000Z","size":159,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T01:41:36.264Z","etag":null,"topics":["ansi","c","c89","deserialization","embedded","hacktoberfest","jsmn","jsmn-token-extraction","json","parser","tokenizer"],"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/lcsmuller.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,"zenodo":null}},"created_at":"2022-01-10T13:41:14.000Z","updated_at":"2025-05-07T00:55:32.000Z","dependencies_parsed_at":"2025-04-10T02:12:12.491Z","dependency_job_id":"0856dc84-756b-4b1a-bbdb-daafc0448a55","html_url":"https://github.com/lcsmuller/jsmn-find","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/lcsmuller/jsmn-find","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcsmuller%2Fjsmn-find","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcsmuller%2Fjsmn-find/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcsmuller%2Fjsmn-find/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcsmuller%2Fjsmn-find/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lcsmuller","download_url":"https://codeload.github.com/lcsmuller/jsmn-find/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lcsmuller%2Fjsmn-find/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279290299,"owners_count":26141133,"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-17T02:00:07.504Z","response_time":56,"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":["ansi","c","c89","deserialization","embedded","hacktoberfest","jsmn","jsmn-token-extraction","json","parser","tokenizer"],"created_at":"2024-09-24T21:20:33.153Z","updated_at":"2025-10-17T05:37:35.075Z","avatar_url":"https://github.com/lcsmuller.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSMN-FIND\n\njsmn-find is an ANSI C add-on for the minimalistic JSON tokenizer\n[jsmn](https://github.com/zserge/jsmn), it offers a familiar and\nzero-allocation design. Its serializer counterpart can be found\nat [json-build](https://github.com/lcsmuller/json-build).\n\n## Dependencies\n\n* [jsmn](https://github.com/zserge/jsmn) - Minimalistic JSON parser\n* [oa_hash](https://github.com/lcsmuller/oa-hash) - A lightweight\nsingle-header open-addressing hashtable implementation in ANSI C\n\n## Design\n\njsmn-find organizes jsmn's JSON tokens under a hashtable so that they can be\nsearched for in linear time.\n\n## Usage\n\nDownload `jsmn-find.h` and the [dependencies](#dependencies) should be visible \nto your linker search path:\n\n#### load (zero-allocation)\n```c\n#include \"jsmn.h\"\n#include \"jsmn-find.h\"\n\n...\njsmnf_table table[256];\njsmnf_loader loader;\n\njsmnf_init(\u0026loader);\nlong r = jsmnf_load(\u0026loader, json, strlen(json), table, 256);\nif (r \u003c 0) error();\n```\n\n#### auto load (allocate memory for jsmnf_table automatically)\n##### jsmn_parse_auto\n\n```c\njsmn_parser parser;\njsmntok_t *toks = NULL;\nunsigned num_tokens = 0;\n\njsmn_init(\u0026parser);\nlong r = jsmn_parse_auto(\u0026parser, json, strlen(json), \u0026toks, \u0026num_tokens);\nif (r \u003c= 0) error();\n\nfree(toks);\n```\n\n##### jsmnf_load_auto\n\n```c\njsmnf_loader loader;\njsmnf_table *table = NULL;\nsize_t table_len = 0;\n\njsmnf_init(\u0026loader);\nlong r = jsmnf_load_auto(\u0026loader, json, strlen(json), \u0026table, \u0026table_len);\nif (r \u003c= 0) error();\n\nfree(table);\n```\n\n#### find by key\n\n```c\nconst jsmnf_pair *f;\n\n// assume the JSON : { \"foo\": { \"bar\": [ true, null, null ] } }\nif ((f = jsmnf_find(loader.root, \"foo\", strlen(\"foo\")))) {\n    // Found: { \"bar\" : [ true, null, null ] }\n    printf(\"Found: %.*s\\n\", f-\u003ev-\u003eend - f-\u003ev-\u003estart, json + f-\u003ev-\u003estart);\n    if ((f = jsmnf_find(f, \"bar\", 3))) {\n        // Found: [ true, null, null ]\n        printf(\"Found: %.*s\\n\", f-\u003ev-\u003eend - f-\u003ev-\u003estart, json + f-\u003ev-\u003estart);\n        if ((f = jsmnf_find(f, \"0\", 1))) {\n            // Found: true\n            printf(\"Found: %.*s\\n\", f-\u003ev-\u003eend - f-\u003ev-\u003estart, json + f-\u003ev-\u003estart);\n        }\n    }\n}\n```\n\n#### index access for arrays\n\n```c\nconst jsmnf_pair *f;\n\n// assume the JSON : [ false, [ true ] ]\nf = \u0026loader.root-\u003efields[1];\nprintf(\"Found: %.*s\\n\", f-\u003ev-\u003eend - f-\u003ev-\u003estart, json + f-\u003ev-\u003estart); // Found: [ true ]\nf = \u0026f-\u003efields[0]; // get nested array\nprintf(\"Found: %.*s\\n\", f-\u003ev-\u003eend - f-\u003ev-\u003estart, json + f-\u003ev-\u003estart); // Found: true\n\n// looping over array\nfor (int i = 0; loader.root-\u003esize; ++i) {\n    f = \u0026loader.root-\u003efields[i];\n    printf(\"%.*s \", f-\u003ev-\u003eend - f-\u003ev-\u003estart, json + f-\u003ev-\u003estart);\n}\n```\n\n#### find by path\n\n```c\n// assume the JSON : [ false, false, [ false, [ { \"b\":true } ] ] ]\nchar *path[] = { \"2\", \"1\", \"0\", \"b\" }; // array keys are the same as its indexes\nconst jsmnf_pair *f;\n\nif ((f = jsmnf_find_path(\u0026loader.root, path, sizeof(path) / sizeof *path))) {\n    // Found: true\n    printf(\"Found: %.*s\\n\", (int)f-\u003ev-\u003eend - f-\u003ev-\u003estart, json + f-\u003ev-\u003estart);\n}\n```\n\njsmn-find is single-header and should be compatible with jsmn additional macros for more complex uses cases. `#define JSMN_STATIC` hides all jsmn-find API symbols by making them static. Also, if you want to include `jsmn-find.h` from multiple C files, to avoid duplication of symbols you may define `JSMN_HEADER` macro.\n\n```c\n/* In every .c file that uses jsmn include only declarations: */\n#define JSMN_HEADER\n#include \"jsmn.h\"\n#include \"jsmn-find.h\"\n\n/* Additionally, create one jsmn-find.c file for jsmn-find implementation: */\n#include \"jsmn.h\"\n#include \"jsmn-find.h\"\n```\n\n## API\n\n* `jsmnf_init()` - initialize a `jsmnf_loader`\n* `jsmnf_load()` - populate `jsmnf_table` table with JSMN tokens\n* `jsmnf_find()` - locate a `jsmnf_pair` by its associated key\n* `jsmnf_find_path()` - locate a `jsmnf_pair` by its full key path\n\n### Misc\n\n* `jsmn_parse_auto()` - `jsmn_parse()` counterpart that automatically allocates the necessary amount of tokens\n* `jsmnf_load_auto()` - `jsmnf_load()` counterpart that automatically allocates the necessary amount of pairs\n* `jsmnf_unescape()` - unescape a Unicode string\n\n## Other Info\n\nThis software is distributed under [MIT license](www.opensource.org/licenses/mit-license.php),\nso feel free to integrate it in your commercial products.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcsmuller%2Fjsmn-find","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flcsmuller%2Fjsmn-find","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flcsmuller%2Fjsmn-find/lists"}