Giter VIP home page Giter VIP logo

jsmn's Introduction

JSMN

Build Status

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 https://github.com/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). And 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.

Usage

Download jsmn.h, include it, done.

#include "jsmn.h"

...
jsmn_parser p;
jsmntok_t t[128]; /* We expect no more than 128 JSON tokens */

jsmn_init(&p);
r = jsmn_parse(&p, s, strlen(s), t, 128); // "s" is the char array holding the json content

Since jsmn is a single-header, header-only library, for more complex use cases you might need to define additional macros. #define JSMN_STATIC hides all jsmn API symbols by making them static. Also, if you want to include jsmn.h from multiple C files, to avoid duplication of symbols you may define JSMN_HEADER macro.

/* In every .c file that uses jsmn include only declarations: */
#define JSMN_HEADER
#include "jsmn.h"

/* Additionally, create one jsmn.c file for jsmn implementation: */
#include "jsmn.h"

API

Token types are described by jsmntype_t:

typedef enum {
	JSMN_UNDEFINED = 0,
	JSMN_OBJECT = 1 << 0,
	JSMN_ARRAY = 1 << 1,
	JSMN_STRING = 1 << 2,
	JSMN_PRIMITIVE = 1 << 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:

jsmn_parser parser;
jsmntok_t tokens[10];

jsmn_init(&parser);

// js - pointer to JSON string
// tokens - an array of tokens available
// 10 - number of tokens available
jsmn_parse(&parser, js, strlen(js), tokens, 10);

This will create a parser, and then it tries to parse up to 10 JSON tokens from the js string.

A non-negative return value of jsmn_parse 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 number 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 JSMN_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 JSMN_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.

jsmn's People

Contributors

abalkin avatar baskerville avatar benbe avatar crondaemon avatar drbitboy avatar elelay avatar elkantor avatar frnknstn avatar ghane avatar goriy avatar ivankravets avatar lyokha avatar macgritsch avatar olmokramer avatar pks-t avatar pt300 avatar simonsj avatar utoni avatar zlolik avatar zserge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsmn's Issues

Create "all-in-one" function to allocate memory and parse

To make it a bit easier to use the tow-stage-parsing method a helper-function could be added. It is not reasonable for everyone to call the init-function jsmn_init() a second time (to reset the position).
Again, the functions name is not sensful (you could chose one) but I think the function it self should be correct (if not, please tell me then I can fix it in my own code ;-))

jsmntok_t *jsmn_parseV2(const char *js, size_t len, unsigned int *num_tokens)
{
    if (num_tokens)
    {
        *num_tokens = 0;
    }

    jsmn_parser parser;
    jsmn_init(&parser);

    int ret = jsmn_parse(&parser, js, len, NULL, 0);
    if (ret <= 0)
    {
        return NULL;
    }

    jsmntok_t *tokens = (jsmntok_t *)calloc(ret, sizeof(jsmntok_t));
    if (!tokens)
    {
        return NULL;
    }

    jsmn_init(&parser); // reset it

    ret = jsmn_parse(&parser, js, len, tokens, ret);
    if (ret <= 0)
    {
        free(tokens);

        return NULL;
    }

    if (num_tokens)
    {
        *num_tokens = ret;
    }

    return tokens;
}

this function could be used like this:

jsmntok_t *tokens = jsmn_parseV2(json_data, json_length, NULL);
if (tokens)
{
    //work with tokens

    free(tokens);
}

or like this:

unsigned int token_count;
jsmntok_t *tokens = jsmn_parseV2(json_data, json_length, &token_count);
if (tokens && token_count)
{
    // work with token_count tokens

    free(tokens);
}

primitive type can't be properly used

I guess I found a bug.

If you use the primitive type and want to know either it is null, a boolean or a numeric, you check the words, for example if("false" == primitive.value). The advice just to check the first char is useless to me and I guess so for many C-programmers, because if a 4 Byte numeric is accidentially the ascii-representation of the word "null" or "true" it cannot be handled. Just checking the first char increases the set of numbers, in which errors occure, a lot. If You have any suggestion about this, please let me know.

Example: 0x6e756c6c is both, a valid integer and the "null" chars.

If it is my fault, please let me know which would be a proper solution for this problem.

if i didn't point out what the problem is, let me know and I will enlarge the description.

best regards, christian


Enhancement for denoting "key" : value pairs

Hi ZSerge,

I have added a functionality to help make sure two tokens have a ':' between them by adding a "valueof" field to the token structure. In the token after the ':' the valueof will point to the token before the ':', and for all other tokens it will be -1 (in the same way a token will point to its parent when this is enabled).

.c file is attached, changes in .h are:
typedef struct {
jsmntype_t type;
int start;
int end;
int size;
int valueof;

ifdef JSMN_PARENT_LINKS

    int parent;

endif

} jsmntok_t;

/**

  • JSON parser. Contains an array of token blocks available. Also stores
  • the string being parsed now and current position in that string
    /
    typedef struct {
    unsigned int pos; /
    offset in the JSON string /
    int toknext; /
    next token to allocate /
    int toksuper; /
    superior token node, e.g parent object or array /
    int nextisval; /
    flag: next token is value of previous */
    } jsmn_parser;

Hope you find this useful!


Incorrect parsing of JSON string when JSMN_PARENT_LINKS switch is enabled

When using this library for parsing JSON on STM32F4 microcontroller with JSMN_PARENT_LINKS I get unexpected structure of jsmntok_t array. It is not corresponding to my input JSON string:

{"cmd":"mo_init_q","qb": [1.1, 1.2, 1.3],"qe": [2.1, 2.2, 2.3],"some": [{"lib":"some.a", "src": "some.c", "ver": 100},{"lib":"another.a", "src": "another.c", "ver": 50}]}

And it also contains incorrect type properties. May be they have not been set at all and contain some "garbage".

The following text is data of token array from the debugger:
{{type = JSMN_OBJECT, start = 0, end = 172, size = 8, parent = 3}, {type = JSMN_ARRAY, start = 5, end = 0, size = 3, parent = 8}, {type = 17, start = 0, end = 3, size = 20, parent = 22}, {type = JSMN_PRIMITIVE, start = 2, end = 25, size = 40, parent = 3}, {type = JSMN_PRIMITIVE, start = 26, end = 29, size = 0, parent = 0}, {type = 31, start = 34, end = 0, size = 0, parent = 36}, {type = 39, start = 0, end = 3, size = 42, parent = 44}, {type = JSMN_PRIMITIVE, start = 2, end = 47, size = 62, parent = 3}, {type = JSMN_PRIMITIVE, start = 48, end = 51, size = 0, parent = 0}, {type = 53, start = 56, end = 0, size = 0, parent = 58}, {type = 61, start = 0, end = 3, size = 64, parent = 68}, {type = JSMN_PRIMITIVE, start = 2, end = 71, size = 171, parent = 2}, {type = JSMN_OBJECT, start = 72, end = 118, size = 6, parent = 3}, {type = 74, start = 77, end = 0, size = 3, parent = 81}, {type = 87, start = 0, end = 3, size = 91, parent = 94}, {type = JSMN_PRIMITIVE, start = 3, end = 98, size = 104, parent = 0}, {type = JSMN_STRING, start = 108, end = 111, size = 0, parent = 0}, {type = 114, start = 117, end = 0, size = 1, parent = 119}, {type = 170, start = 6, end = 3, size = 121, parent = 124}, {type = JSMN_PRIMITIVE, start = 3, end = 128, size = 137, parent = 0}, {type = JSMN_STRING, start = 141, end = 144, size = 0, parent = 3}, {type = 148, start = 157, end = 0, size = 3, parent = 161}, {type = 164, start = 0, end = 0, size = 167, parent = 169}, {type = JSMN_PRIMITIVE, start = 0, end = 0, size = 0, parent = 0} <repeats 77 times>}

There is also screeshoot of debugger info from my toolchain in annex


jsmn_parse requires extra loop over tokens array to know number of tokens have been extracted

It looks there is no quick way to know how many tokens have been pushed into "jsmntok_t *tokens" param of jsmn_parse method.

To understand how many tokens have been extracted user should make an extra iteration over tokens array. The extra iteration should be done before calling jsmn_parse method. It is necessary to init jsmntype_t member of every tokens array member by an invalid value (-1 for example). Once jsmn_parse returns JSMN_SUCCESS the invalid value of jsmntype_t member can be used to ensure end of extracted data reached.


Empty arrays or objects

Hi,
the parser won't add the tokens of arrays with 2 elements or less, nor will it add the tokens of empty objects. In case of an empty object that is a value, the next pair will even be omitted!
an example json file :

{ "height":10,
"layers":[
{
"data":[6,6],
"height":10,
"name":"Calque de Tile 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":10,
"x":0,
"y":0
}],
"orientation":"orthogonal",
"properties":
{

},

"tileheight":32,
"tilesets":[
{
"firstgid":1,
"image":"../images/tiles.png",
"imageheight":64,
"imagewidth":160,
"margin":0,
"name":"Tiles",
"properties":{},
"spacing":0,
"tileheight":32,
"tilewidth":32
}],
"tilewidth":32,
"version":1,
"width":10
}

the "data" array won't be parsed correctly (while if we add a space after the coma it will work fine, or if we put 3 members without spaces such as [5,5,5]) and the "spacing":0 pair won't have any tokens. The parsing will fail if a space is added between the brackets ( "properties":{ }, intead of "properties":{}, )

Is there a way to fix it? Thanks


Create token "counter" function.

Create a function to count (or estimate) the number of tokens in the given json string.

For example, I wrote this function that seems to work.

unsigned int jsmn_count(const char *js) {
    unsigned int index, count;
    count = 0;
    for (index = 0; js[index] != '\0'; ++index) {
        switch(js[index]) {
            case '{':
            case '[':
            case ',':
            case ':':
                ++count;
        }
    }
    return count;
}

It usually returns more tokens than is actually needed.

This stays true to the "no dependencies" philosophy. But at the same time it allows the user to avoid guessing how many tokens are in the json.

I only use strict mode, so this function will likely need to be modified for non-strict mode, probably producing a much higher then needed estimate.


Replace funciton returning int instead of jsmnerr_t

When trying to compile the source code with the version 4.6.3 of GCC as C++ code, the compiler complains about conversion between int and jsmnerr_t.

Indeed, for several _parse functions, the return type is set to int whereas they always return one of the values of the jsmnerr_t type.

Replacing their return type by jsmnerr_t solves the issue.

Btw, nice tool. Thanks for sharing :-)


create new Testcases to improve code coverage

Are the last two errors?

js = "{"a": \003 0}";
jsmn_init(&p);
r = jsmn_parse(&p, js, tokens, 10);
check(r == JSMN_ERROR_INVAL);

js = "{\"a\": \"hallo \\u1234\"}";
jsmn_init(&p);
r = jsmn_parse(&p, js, tokens, 10);
check(r == JSMN_SUCCESS);

js = "{\"a\": \"hallo \\i}";
jsmn_init(&p);
r = jsmn_parse(&p, js, tokens, 10);
check(r == JSMN_ERROR_INVAL);

js = "{\"a\": }";
jsmn_init(&p);
r = jsmn_parse(&p, js, tokens, 10);
check(r == JSMN_SUCCESS); // todo is this really correct ????

js = "{\"a\" }";
jsmn_init(&p);
r = jsmn_parse(&p, js, tokens, 10);
check(r == JSMN_SUCCESS); // todo is this really correct ????

Two stage-parsing

Would it be possible to add a function that does an (optional) parsing which returns the required number of tokens for a given JSON string?

The rest could work as it does now. This way it would be possible to handle input of a previously unspecified length and keep all the benefits of the current library.


jsmn_test fails on mac osx 10.8

Administrators-Mac:jsmn administrator$ make test
Latest version of jsmn from bitbucket.

cc -c jsmn_test.c -o jsmn_test.o
cc -L. -ljsmn jsmn_test.o -o jsmn_test
./jsmn_test
FAILED: general test for a simple JSON string (at line 65)

PASSED: 6
FAILED: 1

Administrators-Mac:jsmn administrator$ cc -v
Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix


Key name string vs. value string

I don't know if this is solvable in the existing solution somehow, but when you transverse a token array, how do you distinct between a key name and a value string?

It's fairly important when searching for a given key, that you don't mistake a "value" for a key name.

I propose that the JSMN_STRING be divided into a JSMN_KEY and a JSMN_STRING_PRIMITIVE. (Or something like that.)


Specify string input length

The parse method:
jsmn_parse(jsmn_parser *parser, const char *js, jsmntok_t *tokens, unsigned int num_tokens)

only handles parsing of null terminated strings. This is unfortunate since a common use case is to read the json from file, where the string is not null terminated. To work around this I currently need to read the file into a buffer larger than the file and then zero terminate it. The other alternative is to make a copy of the entire json string once the file has been loaded.

This would easily be solved if I could specify the length of the string when parsing.

Thanks
Patrik


how to parse more complex type (array & objects)

I am just loving with new json parser. It makes embedded designing a lot easier. I have one question. Would it be possible to show an example of how to parse complex tokens? For example:

js = ""x": "value1", "y": "value2", "dsensor": ["s1": 1, "s2": 0], "asensor": ["a1": 1.5, "a2": 0.8] ";

How to check the values?

check(TOKEN_STRING(js, ??????));
check(TOKEN_STRING(js, ??????));
check(TOKEN_STRING(js, ??????));
check(TOKEN_STRING(js, ??????));


Very, very slow with big files.

Hi there,

I have a JSON file with about 9 MB and it takes over 6 seconds to parse it (only one run of "jsmn_parse" because enough tokens are already allocated before time-measurement starts).

Attached is a screenshot of the profiler which shows the lines that are slow.

Only for comparision: the file can be parsed with "NSJSONSerialization" in less than 0.2 seconds (and apple classes are not very fast...)


strict mode should fail parser on invalid object keys / keys lacking values

There does not appear to be a strict check that the key of a key - value pair is a string, as required by the JSON standard.

Should fail strict: { "foo" : "bar", [ 0 ] : "a" }
Should fail strict: { "foo" : "bar", "a" }

Not marking as bug since you're not primarily shooting for strictness, but it does make the process of parsing trickier if you need to guard against ill-formed JSON.

Thanks for this nice project.


Returning jsmnerr_t: change to int

With _#ifdef _cplusplus in the header people might just use your parser in C++ then feed it a long json and be surprised by sizeof(jsmnerr_t) being 1 (thus number of tokens being returned incorrectly). You probably should return int (your count is int). Also, this will get rid of those warnings when an int count is being returned as jsmnerr_t.


Incremental Parsing

This JSON library seems perfect. It lacks only the ability to process documents that are larger than available memory.

In my dream world, successive calls after JSMN_ERROR_PART would somehow continue where the parsing left off.


Whitespace handling in strict mode

In strict mode JSMN fails to parse the value of "Year" in the following example:

{
"Day": 26,
"Month": 9,
"Year": 12
}

This data comes straight from JSON.stringify(data, null, 2) (Firefox 15) and according to json.org ("Whitespace can be inserted between any pair of tokens.") this should be valid JSON.

Thank you for your great work!


type int problematic for size, start and end indicators

Large strings produce weird results when the range of int is exceeded
due to undefined behaviour regarding integer overflow.

Could you either change the type to unsigned int or make
the type configurable (a la

#!c
#ifndef INDEX_TYPE
#define INDEX_TYPE int
#endif

typedef struct {
    jsmntype_t type;
    INDEX_TYPE start;
    INDEX_TYPE end;
    INDEX_TYPE size;
#ifdef JSMN_PARENT_LINKS
    INDEX_TYPE parent;
#endif
} jsmntok_t;

Parsing arrays (and accessing their content)

I am trying to parse arrays and objects in a JSON file, but I can't figure out how this can be done (I have put some example code at http://pastebin.com/8h8XZJbz). My question is, how can one cast an array in a JSON object as an array in C? I believe that JSMN would greatly benefit from an improved documentation and practical examples.


jsmn_util.c - do you want extras?

Thanks for the parser, surprisingly easy to use!

I found I wanted some extra stuff, like unescaping strings and converting jsmntype_t into text. I wrote some stuff (it's in a Git repo on another project - cf. issue #47) and with tests, so I could convert back to .hg and make a pull request.

Do you want extras, given they could be completely omitted and not increase the footprint if there were unwanted?

What about additions that add a (void*) to jsmn_parser and some extra code to jsmn.c, for generating errors?


Passing NULL instead of tokens array causes exception

The overview says "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."

But passing NULL instead of the tokens array causes an exception on jsmn.c:263-268

Seems like there is no check for NULL.


Array-bounds overflow with bad data

Array-bounds read problems when a bad string is passed to the parser.

For example, an input string that is NOT NUL-terminated, and has a partial string-value with a trailing single backslash.

const char *Input = ""x":"va";

Specify input length as 8 characters. The code will attempt to reference Input[8] in jsmn.c at around line 120 where it tried to look at the characters after the backslash. Similarly, if there is an incomplete \uXXXX sequence, without trailing NUL, there will be a buffer overflow there.


wrong parser position after JSMN_ERROR_NOMEM

If after reading the primitive or string, we can not get token, parser->pos becomes invalid

fix :

change in jsmn_parse_primitive and jsmn_parse_string

#!c
if (token == NULL)
  return JSMN_ERROR_NOMEM;

to

#!c

if (token == NULL)
{
  parser->pos = start;
  return JSMN_ERROR_NOMEM;
}

Empty array element parsing

I found out that parsing the string "[a,,b]" produces an array with 2 elements, while a browser interprets it as a 3-element array, where the second is undefined.
I don't know if you will find this useful, but i wrote a patch to parse the empty second array element as an empty string.


jsmntype needs "empty" value

When defining enums, one must always define the 0-entry as a "empty" value.

Eg.

typedef enum {
JSMN_UNDEFINED = 0,
JSMN_OBJECT = 1,
JSMN_ARRAY = 2,
JSMN_KEY = 3,
JSMN_STRING_PRIMITIVE = 4,
JSMN_PRIMITIVE = 5
} jsmntype_t;

This will solve a lot of small issues. (Especially in ANSI C.) The following constructs will now produce "legal" code.

struct my_struct_containing_jsmntype foo = {0};

Or

memset(&foo, 0, sizeof(struct my_struct_containing_jsmntype));

It's a lifesaver.


Documentation out of date

The documentation on
http://zserge.com/jsmn.html
and
http://zserge.bitbucket.org/jsmn.html
is outdated.

Namely:

  1. JSMN_SUCCESS is gone, the number of tokens is returned instead.
  2. jsmn_init_parser(&parser); is now jsmn_init(&parser);
  3. r = jsmn_parse(&parser, js, tokens, 256); maybe should be
    jsmnerr_t r = jsmn_parse(&parser, js, strlen(js), tokens, 256);
    (Additional parameter and show the type of the return value)

Thanks for creating jsmn.

Ludwig Weinzierl


Multiple root elements

Wouldn't it make sense to return an error if multiple root elements are found and JSMN_STRICT is defined? e.g.
"{}{}"
is not valid JSON and jsmn could/should return an error. This code would do the trick:

                        }
                        token->end = parser->pos + 1;
                        parser->toksuper = token->parent;
+                       if (token->parent == -1) {
+#ifdef JSMN_STRICT
+                           // ensure that no junk data is present
+                           for (; js[parser->pos+1] != '\0'; parser->pos++) {
+                               char c;
+                               c = js[parser->pos+1];
+                               if (!isspace(c)) {
+                                   return JSMN_ERROR_JUNK;
+                               }
+                           }
+#endif
+                           break;
+                       }
                        break;
                    }
                    if (token->parent == -1) {

(Note: I hesitate to create a pull request, as I never used HG as well as Bitbucket so far. But if you're willing to merge this and you want to have a pull request, I'll create one of course)


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.