{"id":13628756,"url":"https://github.com/zserge/jsmn","last_synced_at":"2025-05-14T14:08:17.365Z","repository":{"id":38360219,"uuid":"43683082","full_name":"zserge/jsmn","owner":"zserge","description":"Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket","archived":false,"fork":false,"pushed_at":"2024-06-09T11:29:26.000Z","size":289,"stargazers_count":3817,"open_issues_count":93,"forks_count":790,"subscribers_count":143,"default_branch":"master","last_synced_at":"2025-04-09T03:11:37.768Z","etag":null,"topics":["json-data","json-string","parsing"],"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/zserge.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":"2015-10-05T12:32:35.000Z","updated_at":"2025-04-08T15:06:18.000Z","dependencies_parsed_at":"2024-06-18T22:46:54.519Z","dependency_job_id":null,"html_url":"https://github.com/zserge/jsmn","commit_stats":{"total_commits":131,"total_committers":28,"mean_commits":4.678571428571429,"dds":0.5725190839694656,"last_synced_commit":"25647e692c7906b96ffd2b05ca54c097948e879c"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Fjsmn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Fjsmn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Fjsmn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zserge%2Fjsmn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zserge","download_url":"https://codeload.github.com/zserge/jsmn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159700,"owners_count":22024564,"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-data","json-string","parsing"],"created_at":"2024-08-01T22:00:57.067Z","updated_at":"2025-05-14T14:08:17.345Z","avatar_url":"https://github.com/zserge.png","language":"C","funding_links":[],"categories":["JSON","C","Libraries by Language","工具、材料","进程间通信","C++","C Libraries"],"sub_categories":["C \u0026 C++","软件：嵌入式操作系统、驱动、GUI 库等","Json","JSON"],"readme":"JSMN\n====\n\n[![Build Status](https://travis-ci.org/zserge/jsmn.svg?branch=master)](https://travis-ci.org/zserge/jsmn)\n\njsmn (pronounced like 'jasmine') is a minimalistic JSON parser in C.  It can be\neasily integrated into resource-limited or embedded projects.\n\nYou can find more information about JSON format at [json.org][1]\n\nLibrary sources are available at https://github.com/zserge/jsmn\n\nThe web page with some information about jsmn can be found at\n[http://zserge.com/jsmn.html][2]\n\nPhilosophy\n----------\n\nMost JSON parsers offer you a bunch of functions to load JSON data, parse it\nand extract any value by its name. jsmn proves that checking the correctness of\nevery JSON packet or allocating temporary objects to store parsed JSON fields\noften is an overkill. \n\nJSON format itself is extremely simple, so why should we complicate it?\n\njsmn is designed to be\t**robust** (it should work fine even with erroneous\ndata), **fast** (it should parse data on the fly), **portable** (no superfluous\ndependencies or non-standard C extensions). And of course, **simplicity** is a\nkey feature - simple code style, simple algorithm, simple integration into\nother projects.\n\nFeatures\n--------\n\n* compatible with C89\n* no dependencies (even libc!)\n* highly portable (tested on x86/amd64, ARM, AVR)\n* about 200 lines of code\n* extremely small code footprint\n* API contains only 2 functions\n* no dynamic memory allocation\n* incremental single-pass parsing\n* library code is covered with unit-tests\n\nDesign\n------\n\nThe rudimentary jsmn object is a **token**. Let's consider a JSON string:\n\n\t'{ \"name\" : \"Jack\", \"age\" : 27 }'\n\nIt holds the following tokens:\n\n* Object: `{ \"name\" : \"Jack\", \"age\" : 27}` (the whole object)\n* Strings: `\"name\"`, `\"Jack\"`, `\"age\"` (keys and some values)\n* Number: `27`\n\nIn jsmn, tokens do not hold any data, but point to token boundaries in JSON\nstring instead. In the example above jsmn will create tokens like: Object\n[0..31], String [3..7], String [12..16], String [20..23], Number [27..29].\n\nEvery jsmn token has a type, which indicates the type of corresponding JSON\ntoken. jsmn supports the following token types:\n\n* Object - a container of key-value pairs, e.g.:\n\t`{ \"foo\":\"bar\", \"x\":0.3 }`\n* Array - a sequence of values, e.g.:\n\t`[ 1, 2, 3 ]`\n* String - a quoted sequence of chars, e.g.: `\"foo\"`\n* Primitive - a number, a boolean (`true`, `false`) or `null`\n\nBesides start/end positions, jsmn tokens for complex types (like arrays\nor objects) also contain a number of child items, so you can easily follow\nobject hierarchy.\n\nThis approach provides enough information for parsing any JSON data and makes\nit possible to use zero-copy techniques.\n\nUsage\n-----\n\nDownload `jsmn.h`, include it, done.\n\n```\n#include \"jsmn.h\"\n\n...\njsmn_parser p;\njsmntok_t t[128]; /* We expect no more than 128 JSON tokens */\n\njsmn_init(\u0026p);\nr = jsmn_parse(\u0026p, s, strlen(s), t, 128); // \"s\" is the char array holding the json content\n```\n\nSince jsmn is a single-header, header-only library, for more complex use cases\nyou might need to define additional macros. `#define JSMN_STATIC` hides all\njsmn API symbols by making them static. Also, if you want to include `jsmn.h`\nfrom multiple C files, to avoid duplication of symbols you may define  `JSMN_HEADER` macro.\n\n```\n/* In every .c file that uses jsmn include only declarations: */\n#define JSMN_HEADER\n#include \"jsmn.h\"\n\n/* Additionally, create one jsmn.c file for jsmn implementation: */\n#include \"jsmn.h\"\n```\n\nAPI\n---\n\nToken types are described by `jsmntype_t`:\n\n\ttypedef enum {\n\t\tJSMN_UNDEFINED = 0,\n\t\tJSMN_OBJECT = 1 \u003c\u003c 0,\n\t\tJSMN_ARRAY = 1 \u003c\u003c 1,\n\t\tJSMN_STRING = 1 \u003c\u003c 2,\n\t\tJSMN_PRIMITIVE = 1 \u003c\u003c 3\n\t} jsmntype_t;\n\n**Note:** Unlike JSON data types, primitive tokens are not divided into\nnumbers, booleans and null, because one can easily tell the type using the\nfirst character:\n\n* \u003ccode\u003e't', 'f'\u003c/code\u003e - boolean \n* \u003ccode\u003e'n'\u003c/code\u003e - null\n* \u003ccode\u003e'-', '0'..'9'\u003c/code\u003e - number\n\nToken is an object of `jsmntok_t` type:\n\n\ttypedef struct {\n\t\tjsmntype_t type; // Token type\n\t\tint start;       // Token start position\n\t\tint end;         // Token end position\n\t\tint size;        // Number of child (nested) tokens\n\t} jsmntok_t;\n\n**Note:** string tokens point to the first character after\nthe opening quote and the previous symbol before final quote. This was made \nto simplify string extraction from JSON data.\n\nAll job is done by `jsmn_parser` object. You can initialize a new parser using:\n\n\tjsmn_parser parser;\n\tjsmntok_t tokens[10];\n\n\tjsmn_init(\u0026parser);\n\n\t// js - pointer to JSON string\n\t// tokens - an array of tokens available\n\t// 10 - number of tokens available\n\tjsmn_parse(\u0026parser, js, strlen(js), tokens, 10);\n\nThis will create a parser, and then it tries to parse up to 10 JSON tokens from\nthe `js` string.\n\nA non-negative return value of `jsmn_parse` is the number of tokens actually\nused by the parser.\nPassing NULL instead of the tokens array would not store parsing results, but\ninstead the function will return the number of tokens needed to parse the given\nstring. This can be useful if you don't know yet how many tokens to allocate.\n\nIf something goes wrong, you will get an error. Error will be one of these:\n\n* `JSMN_ERROR_INVAL` - bad token, JSON string is corrupted\n* `JSMN_ERROR_NOMEM` - not enough tokens, JSON string is too large\n* `JSMN_ERROR_PART` - JSON string is too short, expecting more JSON data\n\nIf you get `JSMN_ERROR_NOMEM`, you can re-allocate more tokens and call\n`jsmn_parse` once more.  If you read json data from the stream, you can\nperiodically call `jsmn_parse` and check if return value is `JSMN_ERROR_PART`.\nYou will get this error until you reach the end of JSON data.\n\nOther info\n----------\n\nThis software is distributed under [MIT license](http://www.opensource.org/licenses/mit-license.php),\n so feel free to integrate it in your commercial products.\n\n[1]: http://www.json.org/\n[2]: http://zserge.com/jsmn.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzserge%2Fjsmn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzserge%2Fjsmn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzserge%2Fjsmn/lists"}