Clone this repo:
  1. 267f6bb Adding export dir to libjsmn by Vijay Venkatraman · 3 months ago master
  2. cbfa1a0 package version metadata for external/ by Damien Miller · 1 year, 10 months ago nougat-cts-release nougat-dev nougat-dr1-release nougat-mr0.5-release nougat-mr1-cts-release nougat-mr1-dev nougat-mr1-release nougat-mr1.1-release nougat-mr1.2-release nougat-mr1.3-release nougat-mr1.4-release nougat-mr1.5-release nougat-release sdk-release android-7.0.0_r1 android-7.0.0_r12 android-7.0.0_r13 android-7.0.0_r14 android-7.0.0_r15 android-7.0.0_r17 android-7.0.0_r19 android-7.0.0_r21 android-7.0.0_r24 android-7.0.0_r27 android-7.0.0_r28 android-7.0.0_r29 android-7.0.0_r3 android-7.0.0_r30 android-7.0.0_r31 android-7.0.0_r4 android-7.0.0_r5 android-7.0.0_r6 android-7.0.0_r7 android-7.1.0_r1 android-7.1.0_r2 android-7.1.0_r3 android-7.1.0_r4 android-7.1.0_r5 android-7.1.0_r6 android-7.1.0_r7 android-7.1.1_r1 android-7.1.1_r10 android-7.1.1_r11 android-7.1.1_r12 android-7.1.1_r13 android-7.1.1_r14 android-7.1.1_r15 android-7.1.1_r16 android-7.1.1_r17 android-7.1.1_r2 android-7.1.1_r20 android-7.1.1_r21 android-7.1.1_r22 android-7.1.1_r23 android-7.1.1_r24 android-7.1.1_r25 android-7.1.1_r26 android-7.1.1_r27 android-7.1.1_r28 android-7.1.1_r3 android-7.1.1_r4 android-7.1.1_r6 android-7.1.1_r7 android-7.1.1_r8 android-7.1.1_r9 android-cts-7.0_r1 android-cts-7.0_r2 android-cts-7.0_r3 android-cts-7.0_r4 android-cts-7.0_r5 android-cts-7.0_r6 android-cts-7.0_r7 android-cts-7.1_r1 android-cts-7.1_r2 android-cts-7.1_r3 android-n-mr1-preview-1 android-n-mr1-preview-2 android-n-mr2-preview-1
  3. 27b5a35 Initial upload of a minimalistic JSON parser in C. by Edwin Wong · 2 years, 10 months ago lollipop-cts-release lollipop-dev lollipop-mr1-cts-release lollipop-mr1-dev lollipop-mr1-fi-release lollipop-mr1-release lollipop-mr1-wfc-release lollipop-release lollipop-wear-release marshmallow-cts-release marshmallow-dev marshmallow-dr-dev marshmallow-dr-dragon-release marshmallow-dr-release marshmallow-dr1.5-dev marshmallow-dr1.5-release marshmallow-dr1.6-release marshmallow-mr1-dev marshmallow-mr1-release marshmallow-mr2-release marshmallow-mr3-release marshmallow-release master-soong n-iot-preview-2 nougat-mr1-wear-release android-5.0.0_r1 android-5.0.0_r2 android-5.0.0_r3 android-5.0.0_r4 android-5.0.0_r5 android-5.0.0_r5.1 android-5.0.0_r6 android-5.0.0_r7 android-5.0.1_r1 android-5.0.2_r1 android-5.0.2_r3 android-5.1.0_r1 android-5.1.0_r3 android-5.1.0_r4 android-5.1.0_r5 android-5.1.1_r1 android-5.1.1_r10 android-5.1.1_r12 android-5.1.1_r13 android-5.1.1_r14 android-5.1.1_r15 android-5.1.1_r16 android-5.1.1_r17 android-5.1.1_r18 android-5.1.1_r19 android-5.1.1_r2 android-5.1.1_r20 android-5.1.1_r22 android-5.1.1_r23 android-5.1.1_r24 android-5.1.1_r25 android-5.1.1_r26 android-5.1.1_r28 android-5.1.1_r29 android-5.1.1_r3 android-5.1.1_r30 android-5.1.1_r33 android-5.1.1_r34 android-5.1.1_r35 android-5.1.1_r36 android-5.1.1_r37 android-5.1.1_r38 android-5.1.1_r4 android-5.1.1_r5 android-5.1.1_r6 android-5.1.1_r7 android-5.1.1_r8 android-5.1.1_r9 android-6.0.0_r1 android-6.0.0_r11 android-6.0.0_r12 android-6.0.0_r13 android-6.0.0_r2 android-6.0.0_r23 android-6.0.0_r24 android-6.0.0_r25 android-6.0.0_r26 android-6.0.0_r3 android-6.0.0_r4 android-6.0.0_r41 android-6.0.0_r5 android-6.0.0_r6 android-6.0.0_r7 android-6.0.1_r1 android-6.0.1_r10 android-6.0.1_r11 android-6.0.1_r12 android-6.0.1_r13 android-6.0.1_r16 android-6.0.1_r17 android-6.0.1_r18 android-6.0.1_r20 android-6.0.1_r21 android-6.0.1_r22 android-6.0.1_r24 android-6.0.1_r25 android-6.0.1_r26 android-6.0.1_r27 android-6.0.1_r28 android-6.0.1_r3 android-6.0.1_r30 android-6.0.1_r31 android-6.0.1_r32 android-6.0.1_r33 android-6.0.1_r4 android-6.0.1_r40 android-6.0.1_r41 android-6.0.1_r42 android-6.0.1_r43 android-6.0.1_r45 android-6.0.1_r46 android-6.0.1_r47 android-6.0.1_r48 android-6.0.1_r49 android-6.0.1_r5 android-6.0.1_r50 android-6.0.1_r51 android-6.0.1_r52 android-6.0.1_r53 android-6.0.1_r54 android-6.0.1_r55 android-6.0.1_r56 android-6.0.1_r57 android-6.0.1_r58 android-6.0.1_r59 android-6.0.1_r60 android-6.0.1_r61 android-6.0.1_r62 android-6.0.1_r63 android-6.0.1_r65 android-6.0.1_r66 android-6.0.1_r67 android-6.0.1_r68 android-6.0.1_r69 android-6.0.1_r7 android-6.0.1_r70 android-6.0.1_r72 android-6.0.1_r73 android-6.0.1_r74 android-6.0.1_r77 android-6.0.1_r78 android-6.0.1_r79 android-6.0.1_r8 android-6.0.1_r9 android-cts-5.0_r3 android-cts-5.0_r4 android-cts-5.0_r5 android-cts-5.0_r6 android-cts-5.0_r7 android-cts-5.0_r8 android-cts-5.0_r9 android-cts-5.1_r1 android-cts-5.1_r10 android-cts-5.1_r13 android-cts-5.1_r14 android-cts-5.1_r15 android-cts-5.1_r16 android-cts-5.1_r17 android-cts-5.1_r2 android-cts-5.1_r3 android-cts-5.1_r4 android-cts-5.1_r5 android-cts-5.1_r6 android-cts-5.1_r7 android-cts-5.1_r8 android-cts-5.1_r9 android-cts-6.0_r1 android-cts-6.0_r12 android-cts-6.0_r13 android-cts-6.0_r14 android-cts-6.0_r15 android-cts-6.0_r16 android-cts-6.0_r2 android-cts-6.0_r3 android-cts-6.0_r4 android-cts-6.0_r5 android-cts-6.0_r6 android-cts-6.0_r7 android-cts-6.0_r8 android-cts-6.0_r9 android-m-preview android-m-preview-1 android-m-preview-2 android-n-iot-preview-2 android-n-preview-1 android-n-preview-2 android-n-preview-3 android-n-preview-4 android-n-preview-5 android-wear-5.0.0_r1 android-wear-5.1.0_r1 android-wear-5.1.1_r1 android-wear-7.1.1_r1 android-wear-n-preview-1 android-wear-n-preview-2
  4. 3485037 Initial empty repository by Alex Cheung · 2 years, 10 months ago

JSMN jsmn (pronounced like ‘jasmine’) is a minimalistic JSON parser in C. It can be easily integrated into resource-limited or embedded projects. You can find more information about JSON format at json.org Library sources are available at bitbucket.org/zserge/jsmn The web page with some information about jsmn can be found at http://zserge.com/jsmn.html Philosophy Most JSON parsers offer you a bunch of functions to load JSON data, parse it and extract any value by its name. jsmn proves that checking the correctness of every JSON packet or allocating temporary objects to store parsed JSON fields often is an overkill. JSON format itself is extremely simple, so why should we complicate it? jsmn is designed to be robust (it should work fine even with erroneous data), fast (it should parse data on the fly), portable (no superfluous dependencies or non-standard C extensions). An of course, simplicity is a key feature - simple code style, simple algorithm, simple integration into other projects. Features compatible with C89 no dependencies (even libc!) highly portable (tested on x86/amd64, ARM, AVR) about 200 lines of code extremely small code footprint API contains only 2 functions no dynamic memory allocation incremental single-pass parsing library code is covered with unit-tests Design The rudimentary jsmn object is a token. Let‘s consider a JSON string: ‘{ “name” : “Jack”, “age” : 27 }’ It holds the following tokens: Object: { “name” : “Jack”, “age” : 27} (the whole object) Strings: “name”, “Jack”, “age” (keys and some values) Number: 27 In jsmn, tokens do not hold any data, but point to token boundaries in JSON string instead. In the example above jsmn will create tokens like: Object [0..31], String [3..7], String [12..16], String [20..23], Number [27..29]. Every jsmn token has a type, which indicates the type of corresponding JSON token. jsmn supports the following token types: Object - a container of key-value pairs, e.g.: { “foo”:“bar”, “x”:0.3 } Array - a sequence of values, e.g.: [ 1, 2, 3 ] String - a quoted sequence of chars, e.g.: “foo” Primitive - a number, a boolean (true, false) or null Besides start/end positions, jsmn tokens for complex types (like arrays or objects) also contain a number of child items, so you can easily follow object hierarchy. This approach provides enough information for parsing any JSON data and makes it possible to use zero-copy techniques. Install To clone the repository you should have mercurial installed. Just run: $ hg clone http://bitbucket.org/zserge/jsmn jsmn Repository layout is simple: jsmn.c and jsmn.h are library files, tests are in the jsmn_test.c, you will also find README, LICENSE and Makefile files inside. To build the library, run make. It is also recommended to run make test. Let me know, if some tests fail. If build was successful, you should get a libjsmn.a library. The header file you should include is called “jsmn.h”. API Token types are described by jsmntype_t: typedef enum { JSMN_PRIMITIVE = 0, JSMN_OBJECT = 1, JSMN_ARRAY = 2, JSMN_STRING = 3 } jsmntype_t; Note: Unlike JSON data types, primitive tokens are not divided into numbers, booleans and null, because one can easily tell the type using the first character: ‘t’, ‘f’ - boolean ‘n’ - null ’-', ‘0’..‘9’ - number Token is an object of jsmntok_t type: typedef struct { jsmntype_t type; // Token type int start; // Token start position int end; // Token end position int size; // Number of child (nested) tokens } jsmntok_t; Note: string tokens point to the first character after the opening quote and the previous symbol before final quote. This was made to simplify string extraction from JSON data. All job is done by jsmn_parser object. You can initialize a new parser using: struct jsmn_parser parser; jsmntok_t tokens[10];

// js - pointer to JSON string // tokens - an array of tokens available // 10 - number of tokens available jsmn_init_parser(&parser, js, tokens, 10); This will create a parser, that can parse up to 10 JSON tokens from js string. Later, you can use jsmn_parse(&parser) function to process JSON string with the parser. A non-negative value is the number of tokens actually used by the parser. Passing NULL instead of the tokens array would not store parsing results, but instead the function will return the value of tokens needed to parse the given string. This can be useful if you don't know yet how many tokens to allocate. If something goes wrong, you will get an error. Error will be one of these: JSMN_ERROR_INVAL - bad token, JSON string is corrupted JSMN_ERROR_NOMEM - not enough tokens, JSON string is too large JSMN_ERROR_PART - JSON string is too short, expecting more JSON data If you get JSON_ERROR_NOMEM, you can re-allocate more tokens and call jsmn_parse once more. If you read json data from the stream, you can periodically call jsmn_parse and check if return value is JSON_ERROR_PART. You will get this error until you reach the end of JSON data. Other info This software is distributed under MIT license, so feel free to integrate it in your commercial products.