Fork of my original MQTTGateway

Dependencies:   mbed-http

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers jsmn.h Source File

jsmn.h

00001 #ifndef __JSMN_H_
00002 #define __JSMN_H_
00003 
00004 #include <stddef.h>
00005 
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 /**
00011  * JSON type identifier. Basic types are:
00012  *  o Object
00013  *  o Array
00014  *  o String
00015  *  o Other primitive: number, boolean (true/false) or null
00016  */
00017 typedef enum {
00018     JSMN_UNDEFINED = 0,
00019     JSMN_OBJECT = 1,
00020     JSMN_ARRAY = 2,
00021     JSMN_STRING = 3,
00022     JSMN_PRIMITIVE = 4
00023 } jsmntype_t;
00024 
00025 enum jsmnerr {
00026     /* Not enough tokens were provided */
00027     JSMN_ERROR_NOMEM = -1,
00028     /* Invalid character inside JSON string */
00029     JSMN_ERROR_INVAL = -2,
00030     /* The string is not a full JSON packet, more bytes expected */
00031     JSMN_ERROR_PART = -3
00032 };
00033 
00034 /**
00035  * JSON token description.
00036  * type     type (object, array, string etc.)
00037  * start    start position in JSON data string
00038  * end      end position in JSON data string
00039  */
00040 typedef struct {
00041     jsmntype_t type;
00042     int start;
00043     int end;
00044     int size;
00045 #ifdef JSMN_PARENT_LINKS
00046     int parent;
00047 #endif
00048 } jsmntok_t;
00049 
00050 /**
00051  * JSON parser. Contains an array of token blocks available. Also stores
00052  * the string being parsed now and current position in that string
00053  */
00054 typedef struct {
00055     unsigned int pos; /* offset in the JSON string */
00056     unsigned int toknext; /* next token to allocate */
00057     int toksuper; /* superior token node, e.g parent object or array */
00058 } jsmn_parser;
00059 
00060 /**
00061  * Create JSON parser over an array of tokens
00062  */
00063 void jsmn_init(jsmn_parser *parser);
00064 
00065 /**
00066  * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
00067  * a single JSON object.
00068  */
00069 int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
00070         jsmntok_t *tokens, unsigned int num_tokens);
00071 
00072 #ifdef __cplusplus
00073 }
00074 #endif
00075 
00076 #endif /* __JSMN_H_ */