#ifndef __JSMN_H_1#define __JSMN_H_23#include <stddef.h>45#ifdef __cplusplus6extern "C" {7#endif89/**10* JSON type identifier. Basic types are:11* o Object12* o Array13* o String14* o Other primitive: number, boolean (true/false) or null15*/16typedef enum {17JSMN_UNDEFINED = 0,18JSMN_OBJECT = 1,19JSMN_ARRAY = 2,20JSMN_STRING = 3,21JSMN_PRIMITIVE = 422} jsmntype_t;2324enum jsmnerr {25/* Not enough tokens were provided */26JSMN_ERROR_NOMEM = -1,27/* Invalid character inside JSON string */28JSMN_ERROR_INVAL = -2,29/* The string is not a full JSON packet, more bytes expected */30JSMN_ERROR_PART = -331};3233/**34* JSON token description.35* type type (object, array, string etc.)36* start start position in JSON data string37* end end position in JSON data string38*/39typedef struct {40jsmntype_t type;41int start;42int end;43int size;44#ifdef JSMN_PARENT_LINKS45int parent;46#endif47} jsmntok_t;4849/**50* JSON parser. Contains an array of token blocks available. Also stores51* the string being parsed now and current position in that string52*/53typedef struct {54unsigned int pos; /* offset in the JSON string */55unsigned int toknext; /* next token to allocate */56int toksuper; /* superior token node, e.g parent object or array */57} jsmn_parser;5859/**60* Create JSON parser over an array of tokens61*/62void jsmn_init(jsmn_parser *parser);6364/**65* Run JSON parser. It parses a JSON data string into and array of tokens, each describing66* a single JSON object.67*/68int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,69jsmntok_t *tokens, unsigned int num_tokens);7071#ifdef __cplusplus72}73#endif7475#endif /* __JSMN_H_ */767778