summaryrefslogtreecommitdiff
path: root/json_tokener.h
diff options
context:
space:
mode:
authorEric Haszlakiewicz <erh+git@nimenees.com>2013-03-31 20:05:36 -0500
committerEric Haszlakiewicz <erh+git@nimenees.com>2013-03-31 20:05:36 -0500
commite8161a11bbc2d34c459c5ae9b91750e49a8963e3 (patch)
treeed73a60c84ff96abf07d6baf1d2ec0910ff2a8dc /json_tokener.h
parent889400d946e3e6efa80b336c6c48c63de91d26bb (diff)
Issue #15: add a way to set a JSON_TOKENER_STRICT flag to forbid commas at the end of arrays and objects.
Diffstat (limited to 'json_tokener.h')
-rw-r--r--json_tokener.h22
1 files changed, 21 insertions, 1 deletions
diff --git a/json_tokener.h b/json_tokener.h
index 3da520a..08e5ff7 100644
--- a/json_tokener.h
+++ b/json_tokener.h
@@ -58,7 +58,9 @@ enum json_tokener_state {
json_tokener_state_object_field_end,
json_tokener_state_object_value,
json_tokener_state_object_value_add,
- json_tokener_state_object_sep
+ json_tokener_state_object_sep,
+ json_tokener_state_array_after_sep,
+ json_tokener_state_object_field_start_after_sep
};
struct json_tokener_srec
@@ -80,9 +82,22 @@ struct json_tokener
unsigned int ucs_char;
char quote_char;
struct json_tokener_srec *stack;
+ int flags;
};
/**
+ * Be strict when parsing JSON input. Use caution with
+ * this flag as what is considered valid may become more
+ * restrictive from one release to the next, causing your
+ * code to fail on previously working input.
+ *
+ * This flag is not set by default.
+ *
+ * @see json_tokener_set_flags()
+ */
+#define JSON_TOKENER_STRICT 0x01
+
+/**
* Given an error previously returned by json_tokener_get_error(),
* return a human readable description of the error.
*
@@ -116,6 +131,11 @@ extern void json_tokener_reset(struct json_tokener *tok);
extern struct json_object* json_tokener_parse(const char *str);
extern struct json_object* json_tokener_parse_verbose(const char *str, enum json_tokener_error *error);
+/**
+ * Set flags that control how parsing will be done.
+ */
+extern void json_tokener_set_flags(struct json_tokener *tok, int flags);
+
/**
* Parse a string and return a non-NULL json_object if a valid JSON value
* is found. The string does not need to be a JSON object or array;