build: examples.api: Add necessary linker flags
[jimtcl.git] / jsmn / jsmn.h
blob01ca99c8ec1784118951b87f1c7fd2161c79cb4d
1 #ifndef __JSMN_H_
2 #define __JSMN_H_
4 #include <stddef.h>
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
10 /**
11 * JSON type identifier. Basic types are:
12 * o Object
13 * o Array
14 * o String
15 * o Other primitive: number, boolean (true/false) or null
17 typedef enum {
18 JSMN_UNDEFINED = 0,
19 JSMN_OBJECT = 1,
20 JSMN_ARRAY = 2,
21 JSMN_STRING = 3,
22 JSMN_PRIMITIVE = 4
23 } jsmntype_t;
25 enum jsmnerr {
26 /* Not enough tokens were provided */
27 JSMN_ERROR_NOMEM = -1,
28 /* Invalid character inside JSON string */
29 JSMN_ERROR_INVAL = -2,
30 /* The string is not a full JSON packet, more bytes expected */
31 JSMN_ERROR_PART = -3
34 /**
35 * JSON token description.
36 * @param type type (object, array, string etc.)
37 * @param start start position in JSON data string
38 * @param end end position in JSON data string
40 typedef struct {
41 jsmntype_t type;
42 int start;
43 int end;
44 int size;
45 #ifdef JSMN_PARENT_LINKS
46 int parent;
47 #endif
48 } jsmntok_t;
50 /**
51 * JSON parser. Contains an array of token blocks available. Also stores
52 * the string being parsed now and current position in that string
54 typedef struct {
55 unsigned int pos; /* offset in the JSON string */
56 unsigned int toknext; /* next token to allocate */
57 int toksuper; /* superior token node, e.g parent object or array */
58 } jsmn_parser;
60 /**
61 * Create JSON parser over an array of tokens
63 void jsmn_init(jsmn_parser *parser);
65 /**
66 * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
67 * a single JSON object.
69 int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
70 jsmntok_t *tokens, unsigned int num_tokens);
72 #ifdef __cplusplus
74 #endif
76 #endif /* __JSMN_H_ */