summaryrefslogtreecommitdiff
path: root/json.h
diff options
context:
space:
mode:
Diffstat (limited to 'json.h')
-rw-r--r--json.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/json.h b/json.h
index a767e35..9f4ce74 100644
--- a/json.h
+++ b/json.h
@@ -119,6 +119,33 @@ char *json_cleanup(const char *str);
void json_delete(json_node *node);
/*
+ * Decodes a JSON-encoded string literal
+ * (If you're interested in the decoding JSON in general, see json_decode).
+ * If strict is true, string must be double-quoted,
+ * as is required by the JSON RFC.
+ * Otherwise, the string may be single- or double-quoted.
+ * Also, no whitespace skipping is done, so the caller should only
+ * call this function when it expects **sp to be either " or '
+ *
+ * On success, returns the decoded string and passes that string's length
+ * through *length (which must not be NULL). On failure (parse error),
+ * returns NULL and leaves *length untouched.
+ */
+char *json_decode_string(const char **sp, size_t *length, bool strict);
+
+/*
+ * Encodes a string literal JSON-style using the given quote character,
+ * only escaping characters when necessary
+ * (If you're interested in encoding JSON in general, see json_encode).
+ * Note that using anything but '"' as the quote character will result in
+ * invalid JSON.
+ *
+ * Returns NULL if input is invalid UTF-8 or if an invalid quote character
+ * (such as backslash) is given.
+ */
+char *json_encode_string(const char *str, size_t length, char quote);
+
+/*
* Default: false
*
* If json_escape_unicode is set, json_encode will escape all Unicode