Index: lib/Makefile
===================================================================
--- lib/Makefile	(revision f5bbaba3b2015f039221945431f98027cb3d2d49)
+++ lib/Makefile	(revision f85cb0bd23deb366ea672a46846946c7d6475422)
@@ -13,5 +13,5 @@
 
 # [SH] Program variables
-objects = arc.o base64.o $(EVENT_HANDLER) ftutil.o http_client.o ini.o json.o json_util.o md5.o misc.o oauth.o oauth2.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o ns_parse.o
+objects = arc.o base64.o $(EVENT_HANDLER) ftutil.o http_client.o ini.o md5.o misc.o oauth.o oauth2.o parson.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o ns_parse.o
 
 LFLAGS += -r
Index: b/json.c
===================================================================
--- lib/json.c	(revision f5bbaba3b2015f039221945431f98027cb3d2d49)
+++ 	(revision )
@@ -1,972 +1,0 @@
-/* vim: set et ts=3 sw=3 sts=3 ft=c:
- *
- * Copyright (C) 2012, 2013, 2014 James McLaughlin et al.  All rights reserved.
- * https://github.com/udp/json-parser
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <glib.h>
-
-#include "json.h"
-
-#ifdef _MSC_VER
-   #ifndef _CRT_SECURE_NO_WARNINGS
-      #define _CRT_SECURE_NO_WARNINGS
-   #endif
-#endif
-
-#ifdef __cplusplus
-const struct _json_value json_value_none;    /* zero-d by ctor */
-#else
-const struct _json_value json_value_none = { 0 };
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <math.h>
-
-typedef unsigned int json_uchar;
-
-static unsigned char hex_value(json_char c)
-{
-	if (g_ascii_isdigit(c)) {
-		return c - '0';
-	}
-
-	switch (c) {
-	case 'a': case 'A': return 0x0A;
-	case 'b': case 'B': return 0x0B;
-	case 'c': case 'C': return 0x0C;
-	case 'd': case 'D': return 0x0D;
-	case 'e': case 'E': return 0x0E;
-	case 'f': case 'F': return 0x0F;
-	default: return 0xFF;
-	}
-}
-
-typedef struct {
-	unsigned long used_memory;
-
-	unsigned int uint_max;
-	unsigned long ulong_max;
-
-	json_settings settings;
-	int first_pass;
-
-} json_state;
-
-static void * default_alloc(size_t size, int zero, void * user_data)
-{
-	return zero ? calloc(1, size) : malloc(size);
-}
-
-static void default_free(void * ptr, void * user_data)
-{
-	free(ptr);
-}
-
-static void * json_alloc(json_state * state, unsigned long size, int zero)
-{
-	if ((state->ulong_max - state->used_memory) < size) {
-		return 0;
-	}
-
-	if (state->settings.max_memory
-	    && (state->used_memory += size) > state->settings.max_memory) {
-		return 0;
-	}
-
-	return state->settings.mem_alloc(size, zero, state->settings.user_data);
-}
-
-static int new_value
-        (json_state * state, json_value ** top, json_value ** root, json_value ** alloc, json_type type)
-{
-	json_value * value;
-	int values_size;
-
-	if (!state->first_pass) {
-		value = *top = *alloc;
-		*alloc = (*alloc)->_reserved.next_alloc;
-
-		if (!*root) {
-			*root = value;
-		}
-
-		switch (value->type) {
-		case json_array:
-
-			if (!(value->u.array.values = (json_value **) json_alloc
-			                                      (state, value->u.array.length * sizeof(json_value *),
-			                                      0))) {
-				return 0;
-			}
-
-			value->u.array.length = 0;
-			break;
-
-		case json_object:
-
-			values_size = sizeof(*value->u.object.values) * value->u.object.length;
-
-			if (!((*(void **) &value->u.object.values) = json_alloc
-			                                                     (state, values_size +
-			                                                     ((unsigned long) value->u.object.values),
-			                                                     0))) {
-				return 0;
-			}
-
-			value->_reserved.object_mem = (*(char **) &value->u.object.values) + values_size;
-
-			value->u.object.length = 0;
-			break;
-
-		case json_string:
-
-			if (!(value->u.string.ptr = (json_char *) json_alloc
-			                                    (state, (value->u.string.length + 1) * sizeof(json_char),
-			                                    0))) {
-				return 0;
-			}
-
-			value->u.string.length = 0;
-			break;
-
-		default:
-			break;
-		}
-		;
-
-		return 1;
-	}
-
-	value = (json_value *) json_alloc(state, sizeof(json_value), 1);
-
-	if (!value) {
-		return 0;
-	}
-
-	if (!*root) {
-		*root = value;
-	}
-
-	value->type = type;
-	value->parent = *top;
-
-	if (*alloc) {
-		(*alloc)->_reserved.next_alloc = value;
-	}
-
-	*alloc = *top = value;
-
-	return 1;
-}
-
-#define e_off \
-	((int) (i - cur_line_begin))
-
-#define whitespace \
-case '\n': ++cur_line;  cur_line_begin = i; \
-case ' ': case '\t': case '\r'
-
-#define string_add(b)  \
-	do { if (!state.first_pass) { string [string_length] = b; } ++string_length; } while (0);
-
-static const long
-        flag_next             = 1 << 0,
-        flag_reproc           = 1 << 1,
-        flag_need_comma       = 1 << 2,
-        flag_seek_value       = 1 << 3,
-        flag_escaped          = 1 << 4,
-        flag_string           = 1 << 5,
-        flag_need_colon       = 1 << 6,
-        flag_done             = 1 << 7,
-        flag_num_negative     = 1 << 8,
-        flag_num_zero         = 1 << 9,
-        flag_num_e            = 1 << 10,
-        flag_num_e_got_sign   = 1 << 11,
-        flag_num_e_negative   = 1 << 12,
-        flag_line_comment     = 1 << 13,
-        flag_block_comment    = 1 << 14;
-
-json_value * json_parse_ex(json_settings * settings,
-                           const json_char * json,
-                           size_t length,
-                           char * error_buf)
-{
-	json_char error [json_error_max];
-	unsigned int cur_line;
-	const json_char * cur_line_begin, * i, * end;
-	json_value * top, * root, * alloc = 0;
-	json_state state = { 0 };
-	long flags;
-	long num_digits = 0, num_e = 0;
-	json_int_t num_fraction = 0;
-
-	/* Skip UTF-8 BOM
-	 */
-	if (length >= 3 && ((unsigned char) json [0]) == 0xEF
-	    && ((unsigned char) json [1]) == 0xBB
-	    && ((unsigned char) json [2]) == 0xBF) {
-		json += 3;
-		length -= 3;
-	}
-
-	error[0] = '\0';
-	end = (json + length);
-
-	memcpy(&state.settings, settings, sizeof(json_settings));
-
-	if (!state.settings.mem_alloc) {
-		state.settings.mem_alloc = default_alloc;
-	}
-
-	if (!state.settings.mem_free) {
-		state.settings.mem_free = default_free;
-	}
-
-	memset(&state.uint_max, 0xFF, sizeof(state.uint_max));
-	memset(&state.ulong_max, 0xFF, sizeof(state.ulong_max));
-
-	state.uint_max -= 8; /* limit of how much can be added before next check */
-	state.ulong_max -= 8;
-
-	for (state.first_pass = 1; state.first_pass >= 0; --state.first_pass) {
-		json_uchar uchar;
-		unsigned char uc_b1, uc_b2, uc_b3, uc_b4;
-		json_char * string = 0;
-		unsigned int string_length = 0;
-
-		top = root = 0;
-		flags = flag_seek_value;
-
-		cur_line = 1;
-		cur_line_begin = json;
-
-		for (i = json;; ++i) {
-			json_char b = (i == end ? 0 : *i);
-
-			if (flags & flag_string) {
-				if (!b) {
-					sprintf(error, "Unexpected EOF in string (at %d:%d)", cur_line, e_off);
-					goto e_failed;
-				}
-
-				if (string_length > state.uint_max) {
-					goto e_overflow;
-				}
-
-				if (flags & flag_escaped) {
-					flags &= ~flag_escaped;
-
-					switch (b) {
-					case 'b':  string_add('\b');  break;
-					case 'f':  string_add('\f');  break;
-					case 'n':  string_add('\n');  break;
-					case 'r':  string_add('\r');  break;
-					case 't':  string_add('\t');  break;
-					case 'u':
-
-						if (end - i < 4 ||
-						    (uc_b1 = hex_value(*++i)) == 0xFF || (uc_b2 = hex_value(*++i)) ==
-						    0xFF
-						    || (uc_b3 = hex_value(*++i)) == 0xFF || (uc_b4 = hex_value(*++i)) ==
-						    0xFF) {
-							sprintf(error, "Invalid character value `%c` (at %d:%d)", b,
-							        cur_line, e_off);
-							goto e_failed;
-						}
-
-						uc_b1 = (uc_b1 << 4) | uc_b2;
-						uc_b2 = (uc_b3 << 4) | uc_b4;
-						uchar = (uc_b1 << 8) | uc_b2;
-
-						if ((uchar & 0xF800) == 0xD800) {
-							json_uchar uchar2;
-
-							if (end - i < 6 || (*++i) != '\\' || (*++i) != 'u' ||
-							    (uc_b1 = hex_value(*++i)) == 0xFF ||
-							    (uc_b2 = hex_value(*++i)) == 0xFF
-							    || (uc_b3 = hex_value(*++i)) == 0xFF ||
-							    (uc_b4 = hex_value(*++i)) == 0xFF) {
-								sprintf(error,
-								        "Invalid character value `%c` (at %d:%d)", b,
-								        cur_line, e_off);
-								goto e_failed;
-							}
-
-							uc_b1 = (uc_b1 << 4) | uc_b2;
-							uc_b2 = (uc_b3 << 4) | uc_b4;
-							uchar2 = (uc_b1 << 8) | uc_b2;
-
-							uchar = 0x010000 | ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF);
-						}
-
-						if (sizeof(json_char) >= sizeof(json_uchar) || (uchar <= 0x7F)) {
-							string_add((json_char) uchar);
-							break;
-						}
-
-						if (uchar <= 0x7FF) {
-							if (state.first_pass) {
-								string_length += 2;
-							} else {                    string [string_length++] = 0xC0 |
-								                                               (uchar >>
-								                                                6);
-								                    string [string_length++] = 0x80 |
-								                                               (uchar &
-								                                                0x3F); }
-
-							break;
-						}
-
-						if (uchar <= 0xFFFF) {
-							if (state.first_pass) {
-								string_length += 3;
-							} else {                    string [string_length++] = 0xE0 |
-								                                               (uchar >>
-								                                                12);
-								                    string [string_length++] = 0x80 |
-								                                               ((uchar
-								                                                 >> 6) &
-								                                                0x3F);
-								                    string [string_length++] = 0x80 |
-								                                               (uchar &
-								                                                0x3F); }
-
-							break;
-						}
-
-						if (state.first_pass) {
-							string_length += 4;
-						} else {                string [string_length++] = 0xF0 | (uchar >> 18);
-							                string [string_length++] = 0x80 |
-							                                           ((uchar >>
-							                                             12) & 0x3F);
-							                string [string_length++] = 0x80 |
-							                                           ((uchar >>
-							                                             6) & 0x3F);
-							                string [string_length++] = 0x80 |
-							                                           (uchar & 0x3F); }
-
-						break;
-
-					default:
-						string_add(b);
-					}
-					;
-
-					continue;
-				}
-
-				if (b == '\\') {
-					flags |= flag_escaped;
-					continue;
-				}
-
-				if (b == '"') {
-					if (!state.first_pass) {
-						string [string_length] = 0;
-					}
-
-					flags &= ~flag_string;
-					string = 0;
-
-					switch (top->type) {
-					case json_string:
-
-						top->u.string.length = string_length;
-						flags |= flag_next;
-
-						break;
-
-					case json_object:
-
-						if (state.first_pass) {
-							(*(json_char **) &top->u.object.values) += string_length + 1;
-						} else {
-							top->u.object.values [top->u.object.length].name
-							        = (json_char *) top->_reserved.object_mem;
-
-							top->u.object.values [top->u.object.length].name_length
-							        = string_length;
-
-							(*(json_char **) &top->_reserved.object_mem) += string_length +
-							                                                1;
-						}
-
-						flags |= flag_seek_value | flag_need_colon;
-						continue;
-
-					default:
-						break;
-					}
-					;
-				} else {
-					string_add(b);
-					continue;
-				}
-			}
-
-			if (state.settings.settings & json_enable_comments) {
-				if (flags & (flag_line_comment | flag_block_comment)) {
-					if (flags & flag_line_comment) {
-						if (b == '\r' || b == '\n' || !b) {
-							flags &= ~flag_line_comment;
-							--i; /* so null can be reproc'd */
-						}
-
-						continue;
-					}
-
-					if (flags & flag_block_comment) {
-						if (!b) {
-							sprintf(error, "%d:%d: Unexpected EOF in block comment",
-							        cur_line, e_off);
-							goto e_failed;
-						}
-
-						if (b == '*' && i < (end - 1) && i [1] == '/') {
-							flags &= ~flag_block_comment;
-							++i; /* skip closing sequence */
-						}
-
-						continue;
-					}
-				} else if (b == '/') {
-					if (!(flags & (flag_seek_value | flag_done)) && top->type != json_object) {
-						sprintf(error, "%d:%d: Comment not allowed here", cur_line, e_off);
-						goto e_failed;
-					}
-
-					if (++i == end) {
-						sprintf(error, "%d:%d: EOF unexpected", cur_line, e_off);
-						goto e_failed;
-					}
-
-					switch (b = *i) {
-					case '/':
-						flags |= flag_line_comment;
-						continue;
-
-					case '*':
-						flags |= flag_block_comment;
-						continue;
-
-					default:
-						sprintf(error, "%d:%d: Unexpected `%c` in comment opening sequence",
-						        cur_line, e_off, b);
-						goto e_failed;
-					}
-					;
-				}
-			}
-
-			if (flags & flag_done) {
-				if (!b) {
-					break;
-				}
-
-				switch (b) {
-whitespace:
-					continue;
-
-				default:
-					sprintf(error, "%d:%d: Trailing garbage: `%c`", cur_line, e_off, b);
-					goto e_failed;
-				}
-				;
-			}
-
-			if (flags & flag_seek_value) {
-				switch (b) {
-whitespace:
-					continue;
-
-				case ']':
-
-					if (top && top->type == json_array) {
-						flags = (flags & ~(flag_need_comma | flag_seek_value)) | flag_next;
-					} else {              sprintf(error, "%d:%d: Unexpected ]", cur_line, e_off);
-						              goto e_failed; }
-
-					break;
-
-				default:
-
-					if (flags & flag_need_comma) {
-						if (b == ',') {
-							flags &= ~flag_need_comma;
-							continue;
-						} else { sprintf(error, "%d:%d: Expected , before %c", cur_line, e_off,
-							         b);
-							 goto e_failed; }
-					}
-
-					if (flags & flag_need_colon) {
-						if (b == ':') {
-							flags &= ~flag_need_colon;
-							continue;
-						} else { sprintf(error, "%d:%d: Expected : before %c", cur_line, e_off,
-							         b);
-							 goto e_failed; }
-					}
-
-					flags &= ~flag_seek_value;
-
-					switch (b) {
-					case '{':
-
-						if (!new_value(&state, &top, &root, &alloc, json_object)) {
-							goto e_alloc_failure;
-						}
-
-						continue;
-
-					case '[':
-
-						if (!new_value(&state, &top, &root, &alloc, json_array)) {
-							goto e_alloc_failure;
-						}
-
-						flags |= flag_seek_value;
-						continue;
-
-					case '"':
-
-						if (!new_value(&state, &top, &root, &alloc, json_string)) {
-							goto e_alloc_failure;
-						}
-
-						flags |= flag_string;
-
-						string = top->u.string.ptr;
-						string_length = 0;
-
-						continue;
-
-					case 't':
-
-						if ((end - i) < 3 || *(++i) != 'r' || *(++i) != 'u' || *(++i) != 'e') {
-							goto e_unknown_value;
-						}
-
-						if (!new_value(&state, &top, &root, &alloc, json_boolean)) {
-							goto e_alloc_failure;
-						}
-
-						top->u.boolean = 1;
-
-						flags |= flag_next;
-						break;
-
-					case 'f':
-
-						if ((end - i) < 4 || *(++i) != 'a' || *(++i) != 'l' || *(++i) != 's' ||
-						    *(++i) != 'e') {
-							goto e_unknown_value;
-						}
-
-						if (!new_value(&state, &top, &root, &alloc, json_boolean)) {
-							goto e_alloc_failure;
-						}
-
-						flags |= flag_next;
-						break;
-
-					case 'n':
-
-						if ((end - i) < 3 || *(++i) != 'u' || *(++i) != 'l' || *(++i) != 'l') {
-							goto e_unknown_value;
-						}
-
-						if (!new_value(&state, &top, &root, &alloc, json_null)) {
-							goto e_alloc_failure;
-						}
-
-						flags |= flag_next;
-						break;
-
-					default:
-
-						if (g_ascii_isdigit(b) || b == '-') {
-							if (!new_value(&state, &top, &root, &alloc, json_integer)) {
-								goto e_alloc_failure;
-							}
-
-							if (!state.first_pass) {
-								while (g_ascii_isdigit(b) || b == '+' || b == '-'
-								       || b == 'e' || b == 'E' || b == '.') {
-									if ((++i) == end) {
-										b = 0;
-										break;
-									}
-
-									b = *i;
-								}
-
-								flags |= flag_next | flag_reproc;
-								break;
-							}
-
-							flags &= ~(flag_num_negative | flag_num_e |
-							           flag_num_e_got_sign | flag_num_e_negative |
-							           flag_num_zero);
-
-							num_digits = 0;
-							num_fraction = 0;
-							num_e = 0;
-
-							if (b != '-') {
-								flags |= flag_reproc;
-								break;
-							}
-
-							flags |= flag_num_negative;
-							continue;
-						} else { sprintf(error, "%d:%d: Unexpected %c when seeking value",
-							         cur_line, e_off, b);
-							 goto e_failed; }
-					}
-					;
-				}
-				;
-			} else {
-				switch (top->type) {
-				case json_object:
-
-					switch (b) {
-whitespace:
-						continue;
-
-					case '"':
-
-						if (flags & flag_need_comma) {
-							sprintf(error, "%d:%d: Expected , before \"", cur_line, e_off);
-							goto e_failed;
-						}
-
-						flags |= flag_string;
-
-						string = (json_char *) top->_reserved.object_mem;
-						string_length = 0;
-
-						break;
-
-					case '}':
-
-						flags = (flags & ~flag_need_comma) | flag_next;
-						break;
-
-					case ',':
-
-						if (flags & flag_need_comma) {
-							flags &= ~flag_need_comma;
-							break;
-						}
-
-					default:
-
-						sprintf(error, "%d:%d: Unexpected `%c` in object", cur_line, e_off, b);
-						goto e_failed;
-					}
-					;
-
-					break;
-
-				case json_integer:
-				case json_double:
-
-					if (g_ascii_isdigit(b)) {
-						++num_digits;
-
-						if (top->type == json_integer || flags & flag_num_e) {
-							if (!(flags & flag_num_e)) {
-								if (flags & flag_num_zero) {
-									sprintf(error,
-									        "%d:%d: Unexpected `0` before `%c`",
-									        cur_line, e_off, b);
-									goto e_failed;
-								}
-
-								if (num_digits == 1 && b == '0') {
-									flags |= flag_num_zero;
-								}
-							} else {
-								flags |= flag_num_e_got_sign;
-								num_e = (num_e * 10) + (b - '0');
-								continue;
-							}
-
-							top->u.integer = (top->u.integer * 10) + (b - '0');
-							continue;
-						}
-
-						num_fraction = (num_fraction * 10) + (b - '0');
-						continue;
-					}
-
-					if (b == '+' || b == '-') {
-						if ((flags & flag_num_e) && !(flags & flag_num_e_got_sign)) {
-							flags |= flag_num_e_got_sign;
-
-							if (b == '-') {
-								flags |= flag_num_e_negative;
-							}
-
-							continue;
-						}
-					} else if (b == '.' && top->type == json_integer) {
-						if (!num_digits) {
-							sprintf(error, "%d:%d: Expected digit before `.`", cur_line,
-							        e_off);
-							goto e_failed;
-						}
-
-						top->type = json_double;
-						top->u.dbl = (double) top->u.integer;
-
-						num_digits = 0;
-						continue;
-					}
-
-					if (!(flags & flag_num_e)) {
-						if (top->type == json_double) {
-							if (!num_digits) {
-								sprintf(error, "%d:%d: Expected digit after `.`",
-								        cur_line, e_off);
-								goto e_failed;
-							}
-
-							top->u.dbl += ((double) num_fraction) /
-							              (pow(10, (double) num_digits));
-						}
-
-						if (b == 'e' || b == 'E') {
-							flags |= flag_num_e;
-
-							if (top->type == json_integer) {
-								top->type = json_double;
-								top->u.dbl = (double) top->u.integer;
-							}
-
-							num_digits = 0;
-							flags &= ~flag_num_zero;
-
-							continue;
-						}
-					} else {
-						if (!num_digits) {
-							sprintf(error, "%d:%d: Expected digit after `e`", cur_line,
-							        e_off);
-							goto e_failed;
-						}
-
-						top->u.dbl *=
-						        pow(10,
-						            (double) (flags & flag_num_e_negative ? -num_e : num_e));
-					}
-
-					if (flags & flag_num_negative) {
-						if (top->type == json_integer) {
-							top->u.integer = -top->u.integer;
-						} else {
-							top->u.dbl = -top->u.dbl;
-						}
-					}
-
-					flags |= flag_next | flag_reproc;
-					break;
-
-				default:
-					break;
-				}
-				;
-			}
-
-			if (flags & flag_reproc) {
-				flags &= ~flag_reproc;
-				--i;
-			}
-
-			if (flags & flag_next) {
-				flags = (flags & ~flag_next) | flag_need_comma;
-
-				if (!top->parent) {
-					/* root value done */
-
-					flags |= flag_done;
-					continue;
-				}
-
-				if (top->parent->type == json_array) {
-					flags |= flag_seek_value;
-				}
-
-				if (!state.first_pass) {
-					json_value * parent = top->parent;
-
-					switch (parent->type) {
-					case json_object:
-
-						parent->u.object.values
-						[parent->u.object.length].value = top;
-
-						break;
-
-					case json_array:
-
-						parent->u.array.values
-						[parent->u.array.length] = top;
-
-						break;
-
-					default:
-						break;
-					}
-					;
-				}
-
-				if ((++top->parent->u.array.length) > state.uint_max) {
-					goto e_overflow;
-				}
-
-				top = top->parent;
-
-				continue;
-			}
-		}
-
-		alloc = root;
-	}
-
-	return root;
-
-e_unknown_value:
-
-	sprintf(error, "%d:%d: Unknown value", cur_line, e_off);
-	goto e_failed;
-
-e_alloc_failure:
-
-	strcpy(error, "Memory allocation failure");
-	goto e_failed;
-
-e_overflow:
-
-	sprintf(error, "%d:%d: Too long (caught overflow)", cur_line, e_off);
-	goto e_failed;
-
-e_failed:
-
-	if (error_buf) {
-		if (*error) {
-			strcpy(error_buf, error);
-		} else {
-			strcpy(error_buf, "Unknown error");
-		}
-	}
-
-	if (state.first_pass) {
-		alloc = root;
-	}
-
-	while (alloc) {
-		top = alloc->_reserved.next_alloc;
-		state.settings.mem_free(alloc, state.settings.user_data);
-		alloc = top;
-	}
-
-	if (!state.first_pass) {
-		json_value_free_ex(&state.settings, root);
-	}
-
-	return 0;
-}
-
-json_value * json_parse(const json_char * json, size_t length)
-{
-	json_settings settings = { 0 };
-
-	return json_parse_ex(&settings, json, length, 0);
-}
-
-void json_value_free_ex(json_settings * settings, json_value * value)
-{
-	json_value * cur_value;
-
-	if (!value) {
-		return;
-	}
-
-	value->parent = 0;
-
-	while (value) {
-		switch (value->type) {
-		case json_array:
-
-			if (!value->u.array.length) {
-				settings->mem_free(value->u.array.values, settings->user_data);
-				break;
-			}
-
-			value = value->u.array.values [--value->u.array.length];
-			continue;
-
-		case json_object:
-
-			if (!value->u.object.length) {
-				settings->mem_free(value->u.object.values, settings->user_data);
-				break;
-			}
-
-			value = value->u.object.values [--value->u.object.length].value;
-			continue;
-
-		case json_string:
-
-			settings->mem_free(value->u.string.ptr, settings->user_data);
-			break;
-
-		default:
-			break;
-		}
-		;
-
-		cur_value = value;
-		value = value->parent;
-		settings->mem_free(cur_value, settings->user_data);
-	}
-}
-
-void json_value_free(json_value * value)
-{
-	json_settings settings = { 0 };
-
-	settings.mem_free = default_free;
-	json_value_free_ex(&settings, value);
-}
-
Index: b/json.h
===================================================================
--- lib/json.h	(revision f5bbaba3b2015f039221945431f98027cb3d2d49)
+++ 	(revision )
@@ -1,262 +1,0 @@
-
-/* vim: set et ts=3 sw=3 sts=3 ft=c:
- *
- * Copyright (C) 2012, 2013, 2014 James McLaughlin et al.  All rights reserved.
- * https://github.com/udp/json-parser
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _JSON_H
-#define _JSON_H
-
-#ifndef json_char
-   #define json_char char
-#endif
-
-#ifndef json_int_t
-   #ifndef _MSC_VER
-      #include <inttypes.h>
-      #define json_int_t int64_t
-   #else
-      #define json_int_t __int64
-   #endif
-#endif
-
-#include <stdlib.h>
-
-#ifdef __cplusplus
-
-   #include <string.h>
-
-extern "C"
-{
-
-#endif
-
-typedef struct {
-	unsigned long max_memory;
-	int settings;
-
-	/* Custom allocator support (leave null to use malloc/free)
-	 */
-
-	void * (*mem_alloc)(size_t, int zero, void * user_data);
-	void (* mem_free)(void *, void * user_data);
-
-	void * user_data; /* will be passed to mem_alloc and mem_free */
-
-} json_settings;
-
-#define json_enable_comments  0x01
-
-typedef enum {
-	json_none,
-	json_object,
-	json_array,
-	json_integer,
-	json_double,
-	json_string,
-	json_boolean,
-	json_null
-
-} json_type;
-
-extern const struct _json_value json_value_none;
-
-typedef struct _json_value {
-	struct _json_value * parent;
-
-	json_type type;
-
-	union {
-		int boolean;
-		json_int_t integer;
-		double dbl;
-
-		struct {
-			unsigned int length;
-			json_char * ptr; /* null terminated */
-
-		} string;
-
-		struct {
-			unsigned int length;
-
-			struct {
-				json_char * name;
-				unsigned int name_length;
-
-				struct _json_value * value;
-
-			} * values;
-
-	 #if defined(__cplusplus) && __cplusplus >= 201103L
-			decltype(values) begin() const
-			{  return values; }
-			decltype(values) end() const
-			{  return values + length; }
-	 #endif
-
-		} object;
-
-		struct {
-			unsigned int length;
-			struct _json_value ** values;
-
-	 #if defined(__cplusplus) && __cplusplus >= 201103L
-			decltype(values) begin() const
-			{  return values; }
-			decltype(values) end() const
-			{  return values + length; }
-	 #endif
-
-		} array;
-
-	} u;
-
-	union {
-		struct _json_value * next_alloc;
-		void * object_mem;
-
-	} _reserved;
-
-
-	/* Some C++ operator sugar */
-
-   #ifdef __cplusplus
-
-public:
-
-	inline _json_value ()
-	{
-		memset(this, 0, sizeof(_json_value));
-	}
-
-	inline const struct _json_value &operator [](int index) const
-	{
-		if (type != json_array || index < 0
-		    || ((unsigned int)index) >= u.array.length) {
-			return json_value_none;
-		}
-
-		return *u.array.values [index];
-	}
-
-	inline const struct _json_value &operator [](const char * index) const
-	{
-		if (type != json_object) {
-			return json_value_none;
-		}
-
-		for (unsigned int i = 0; i < u.object.length; ++i) {
-			if (!strcmp(u.object.values [i].name, index)) {
-				return *u.object.values [i].value;
-			}
-		}
-
-		return json_value_none;
-	}
-
-	inline operator const char *() const
-	{
-		switch (type) {
-		case json_string:
-			return u.string.ptr;
-
-		default:
-			return "";
-		}
-		;
-	}
-
-	inline operator json_int_t() const
-	{
-		switch (type) {
-		case json_integer:
-			return u.integer;
-
-		case json_double:
-			return (json_int_t)u.dbl;
-
-		default:
-			return 0;
-		}
-		;
-	}
-
-	inline operator bool() const
-	{
-		if (type != json_boolean) {
-			return false;
-		}
-
-		return u.boolean != 0;
-	}
-
-	inline operator double() const
-	{
-		switch (type) {
-		case json_integer:
-			return (double)u.integer;
-
-		case json_double:
-			return u.dbl;
-
-		default:
-			return 0;
-		}
-		;
-	}
-
-   #endif
-
-} json_value;
-
-json_value * json_parse(const json_char * json,
-                        size_t length);
-
-#define json_error_max 128
-json_value * json_parse_ex(json_settings * settings,
-                           const json_char * json,
-                           size_t length,
-                           char * error);
-
-void json_value_free(json_value *);
-
-
-/* Not usually necessary, unless you used a custom mem_alloc and now want to
- * use a custom mem_free.
- */
-void json_value_free_ex(json_settings * settings,
-                        json_value *);
-
-
-#ifdef __cplusplus
-}    /* extern "C" */
-#endif
-
-#endif
-
-
Index: b/json_util.c
===================================================================
--- lib/json_util.c	(revision f5bbaba3b2015f039221945431f98027cb3d2d49)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/***************************************************************************\
-*                                                                           *
-*  BitlBee - An IRC to IM gateway                                           *
-*  Helper functions for json.c                                              *
-*                                                                           *
-*  Copyright 2012-2012 Wilmer van der Gaast <wilmer@gaast.net>              *
-*                                                                           *
-*  This program is free software; you can redistribute it and/or modify     *
-*  it under the terms of the GNU General Public License as published by     *
-*  the Free Software Foundation; either version 2 of the License, or        *
-*  (at your option) any later version.                                      *
-*                                                                           *
-*  This program is distributed in the hope that it will be useful,          *
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
-*  GNU General Public License for more details.                             *
-*                                                                           *
-*  You should have received a copy of the GNU General Public License along  *
-*  with this program; if not, write to the Free Software Foundation, Inc.,  *
-*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
-*                                                                           *
-****************************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-
-#include "json_util.h"
-
-json_value *json_o_get(const json_value *obj, const json_char *name)
-{
-	int i;
-
-	if (!obj || obj->type != json_object) {
-		return NULL;
-	}
-
-	for (i = 0; i < obj->u.object.length; ++i) {
-		if (strcmp(obj->u.object.values[i].name, name) == 0) {
-			return obj->u.object.values[i].value;
-		}
-	}
-
-	return NULL;
-}
-
-const char *json_o_str(const json_value *obj, const json_char *name)
-{
-	json_value *ret = json_o_get(obj, name);
-
-	if (ret && ret->type == json_string) {
-		return ret->u.string.ptr;
-	} else {
-		return NULL;
-	}
-}
-
-char *json_o_strdup(const json_value *obj, const json_char *name)
-{
-	json_value *ret = json_o_get(obj, name);
-
-	if (ret && ret->type == json_string && ret->u.string.ptr) {
-		return g_memdup(ret->u.string.ptr, ret->u.string.length + 1);
-	} else {
-		return NULL;
-	}
-}
Index: b/json_util.h
===================================================================
--- lib/json_util.h	(revision f5bbaba3b2015f039221945431f98027cb3d2d49)
+++ 	(revision )
@@ -1,35 +1,0 @@
-/***************************************************************************\
-*                                                                           *
-*  BitlBee - An IRC to IM gateway                                           *
-*  Helper functions for json.c                                              *
-*                                                                           *
-*  Copyright 2012-2012 Wilmer van der Gaast <wilmer@gaast.net>              *
-*                                                                           *
-*  This program is free software; you can redistribute it and/or modify     *
-*  it under the terms of the GNU General Public License as published by     *
-*  the Free Software Foundation; either version 2 of the License, or        *
-*  (at your option) any later version.                                      *
-*                                                                           *
-*  This program is distributed in the hope that it will be useful,          *
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
-*  GNU General Public License for more details.                             *
-*                                                                           *
-*  You should have received a copy of the GNU General Public License along  *
-*  with this program; if not, write to the Free Software Foundation, Inc.,  *
-*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
-*                                                                           *
-****************************************************************************/
-
-#include "json.h"
-
-#define JSON_O_FOREACH(o, k, v) \
-	char *k; json_value *v; int __i; \
-	for (__i = 0; (__i < (o)->u.object.length) && \
-	     (k = (o)->u.object.values[__i].name) && \
-	     (v = (o)->u.object.values[__i].value); \
-	     __i ++)
-
-json_value *json_o_get(const json_value *obj, const json_char *name);
-const char *json_o_str(const json_value *obj, const json_char *name);
-char *json_o_strdup(const json_value *obj, const json_char *name);
Index: lib/oauth2.c
===================================================================
--- lib/oauth2.c	(revision f5bbaba3b2015f039221945431f98027cb3d2d49)
+++ lib/oauth2.c	(revision f85cb0bd23deb366ea672a46846946c7d6475422)
@@ -42,7 +42,10 @@
 #include "oauth2.h"
 #include "oauth.h"
-#include "json.h"
-#include "json_util.h"
+#include "parson.h"
 #include "url.h"
+
+#define JSON_O_FOREACH(o, k, v) \
+    const char *k; const JSON_Value *v; int __i; \
+    for (__i = 0; json_object_get_tuple(o, __i, &k, &v); __i++)
 
 char *oauth2_url(const struct oauth2_service *sp)
@@ -113,23 +116,18 @@
 }
 
-static char* oauth2_parse_error(json_value *e)
+static char* oauth2_parse_error(const JSON_Value *e)
 {
 	/* This does a reasonable job with some of the flavours of error
 	   responses I've seen. Because apparently it's not standardised. */
 
-	if (e->type == json_object) {
+	if (json_type(e) == JSONObject) {
 		/* Facebook style */
-		const char *msg = json_o_str(e, "message");
-		const char *type = json_o_str(e, "type");
-		json_value *code_o = json_o_get(e, "code");
-		int code = 0;
-
-		if (code_o && code_o->type == json_integer) {
-			code = code_o->u.integer;
-		}
-
+		const char *msg = json_object_get_string(json_object(e), "message");
+		const char *type = json_object_get_string(json_object(e), "type");
+		JSON_Value *code_o = json_object_get_value(json_object(e), "code");
+		int code = json_value_get_integer(code_o);
 		return g_strdup_printf("Error %d: %s", code, msg ? msg : type ? type : "Unknown error");
-	} else if (e->type == json_string) {
-		return g_strdup(e->u.string.ptr);
+	} else if (json_type(e) == JSONString) {
+		return g_strdup(json_string(e));
 	}
 	return NULL;
@@ -156,18 +154,18 @@
 	if (content_type && (strstr(content_type, "application/json") ||
 	                     strstr(content_type, "text/javascript"))) {
-		json_value *js = json_parse(req->reply_body, req->body_size);
-		if (js && js->type == json_object) {
-			JSON_O_FOREACH(js, k, v){
+		JSON_Value *js = json_parse_string(req->reply_body);
+		if (js && json_type(js) == JSONObject) {
+			JSON_O_FOREACH(json_object(js), k, v){
 				if (strcmp(k, "error") == 0) {
 					error = oauth2_parse_error(v);
 				}
-				if (v->type != json_string) {
+				if (json_type(v) != JSONString) {
 					continue;
 				}
 				if (strcmp(k, "access_token") == 0) {
-					atoken = g_strdup(v->u.string.ptr);
+					atoken = g_strdup(json_string(v));
 				}
 				if (strcmp(k, "refresh_token") == 0) {
-					rtoken = g_strdup(v->u.string.ptr);
+					rtoken = g_strdup(json_string(v));
 				}
 			}
Index: protocols/twitter/twitter_lib.c
===================================================================
--- protocols/twitter/twitter_lib.c	(revision f5bbaba3b2015f039221945431f98027cb3d2d49)
+++ protocols/twitter/twitter_lib.c	(revision f85cb0bd23deb366ea672a46846946c7d6475422)
@@ -36,5 +36,5 @@
 #include "base64.h"
 #include "twitter_lib.h"
-#include "json_util.h"
+#include "parson.h"
 #include <ctype.h>
 #include <errno.h>
@@ -64,4 +64,8 @@
 	gboolean from_filter;
 };
+
+#define JSON_O_FOREACH(o, k, v) \
+    const char *k; const JSON_Value *v; int __i; \
+    for (__i = 0; json_object_get_tuple(o, __i, &k, &v); __i++)
 
 /**
@@ -166,5 +170,5 @@
 {
 	static char *ret = NULL;
-	json_value *root, *err;
+	JSON_Value *root, *err;
 
 	g_free(ret);
@@ -172,9 +176,10 @@
 
 	if (req->body_size > 0) {
-		root = json_parse(req->reply_body, req->body_size);
-		err = json_o_get(root, "errors");
-		if (err && err->type == json_array && (err = err->u.array.values[0]) &&
-		    err->type == json_object) {
-			const char *msg = json_o_str(err, "message");
+		root = json_parse_string(req->reply_body);
+		err = json_object_get_value(json_object(root), "errors");
+		if (err && json_type(err) == JSONArray &&
+		    (err = json_array_get_value(json_array(err), 0)) &&
+		    json_type(err) == JSONObject) {
+			const char *msg = json_object_get_string(json_object(err), "message");
 			if (msg) {
 				ret = g_strdup_printf("%s (%s)", req->status_string, msg);
@@ -189,10 +194,10 @@
 /* WATCH OUT: This function might or might not destroy your connection.
    Sub-optimal indeed, but just be careful when this returns NULL! */
-static json_value *twitter_parse_response(struct im_connection *ic, struct http_request *req)
+static JSON_Value *twitter_parse_response(struct im_connection *ic, struct http_request *req)
 {
 	gboolean logging_in = !(ic->flags & OPT_LOGGED_IN);
 	gboolean periodic;
 	struct twitter_data *td = ic->proto_data;
-	json_value *ret;
+	JSON_Value *ret;
 	char path[64] = "", *s;
 
@@ -232,5 +237,5 @@
 	}
 
-	if ((ret = json_parse(req->reply_body, req->body_size)) == NULL) {
+	if ((ret = json_parse_string(req->reply_body)) == NULL) {
 		imcb_error(ic, "Could not retrieve %s: %s",
 		           path, "XML parse error");
@@ -259,7 +264,7 @@
  * Fill a list of ids.
  */
-static gboolean twitter_xt_get_friends_id_list(json_value *node, struct twitter_xml_list *txl)
-{
-	json_value *c;
+static gboolean twitter_xt_get_friends_id_list(JSON_Value *node, struct twitter_xml_list *txl)
+{
+	JSON_Array *c;
 	int i;
 
@@ -267,21 +272,18 @@
 	txl->type = TXL_ID;
 
-	c = json_o_get(node, "ids");
-	if (!c || c->type != json_array) {
+	if (!(c = json_object_get_array(json_object(node), "ids"))) {
 		return FALSE;
 	}
 
-	for (i = 0; i < c->u.array.length; i++) {
-		if (c->u.array.values[i]->type != json_integer) {
-			continue;
-		}
+	for (i = 0; i < json_array_get_count(c); i++) {
+		jint id = json_array_get_integer(c, i);
 
 		txl->list = g_slist_prepend(txl->list,
-		                            g_strdup_printf("%" PRIu64, c->u.array.values[i]->u.integer));
-	}
-
-	c = json_o_get(node, "next_cursor");
-	if (c && c->type == json_integer) {
-		txl->next_cursor = c->u.integer;
+		                            g_strdup_printf("%lld", id));
+	}
+
+	JSON_Value *next = json_object_get_value(json_object(node), "next_cursor");
+	if (next && json_type(next) == JSONInteger) {
+		txl->next_cursor = json_integer(next);
 	} else {
 		txl->next_cursor = -1;
@@ -299,5 +301,5 @@
 {
 	struct im_connection *ic;
-	json_value *parsed;
+	JSON_Value *parsed;
 	struct twitter_xml_list *txl;
 	struct twitter_data *td;
@@ -337,5 +339,5 @@
 }
 
-static gboolean twitter_xt_get_users(json_value *node, struct twitter_xml_list *txl);
+static gboolean twitter_xt_get_users(JSON_Value *node, struct twitter_xml_list *txl);
 static void twitter_http_get_users_lookup(struct http_request *req);
 
@@ -378,5 +380,5 @@
 {
 	struct im_connection *ic = req->data;
-	json_value *parsed;
+	JSON_Value *parsed;
 	struct twitter_xml_list *txl;
 	GSList *l = NULL;
@@ -410,15 +412,15 @@
 }
 
-struct twitter_xml_user *twitter_xt_get_user(const json_value *node)
+struct twitter_xml_user *twitter_xt_get_user(const JSON_Object *node)
 {
 	struct twitter_xml_user *txu;
-	json_value *jv;
+	
+	if (!node)
+		return NULL;
 
 	txu = g_new0(struct twitter_xml_user, 1);
-	txu->name = g_strdup(json_o_str(node, "name"));
-	txu->screen_name = g_strdup(json_o_str(node, "screen_name"));
-
-	jv = json_o_get(node, "id");
-	txu->uid = jv->u.integer;
+	txu->name = g_strdup(json_object_get_string(node, "name"));
+	txu->screen_name = g_strdup(json_object_get_string(node, "screen_name"));
+	txu->uid = json_object_get_integer(node, "id");
 
 	return txu;
@@ -430,5 +432,5 @@
  *  - all <user>s from the <users> element.
  */
-static gboolean twitter_xt_get_users(json_value *node, struct twitter_xml_list *txl)
+static gboolean twitter_xt_get_users(JSON_Value *node, struct twitter_xml_list *txl)
 {
 	struct twitter_xml_user *txu;
@@ -438,12 +440,16 @@
 	txl->type = TXL_USER;
 
-	if (!node || node->type != json_array) {
+	if (json_type(node) != JSONArray) {
 		return FALSE;
 	}
-
+	
 	// The root <users> node should hold the list of users <user>
 	// Walk over the nodes children.
-	for (i = 0; i < node->u.array.length; i++) {
-		txu = twitter_xt_get_user(node->u.array.values[i]);
+	JSON_Array *arr = json_array(node);
+	for (i = 0; i < json_array_get_count(arr); i++) {
+		JSON_Object *o = json_array_get_object(arr, i);
+		if (!o)
+			continue;
+		txu = twitter_xt_get_user(o);
 		if (txu) {
 			txl->list = g_slist_prepend(txl->list, txu);
@@ -460,5 +466,5 @@
 #endif
 
-static void expand_entities(char **text, const json_value *node);
+static void expand_entities(char **text, const JSON_Object *node);
 
 /**
@@ -470,10 +476,10 @@
  *  - the user in a twitter_xml_user struct.
  */
-static struct twitter_xml_status *twitter_xt_get_status(const json_value *node)
+static struct twitter_xml_status *twitter_xt_get_status(const JSON_Object *node)
 {
 	struct twitter_xml_status *txs;
-	const json_value *rt = NULL;
-
-	if (node->type != json_object) {
+	const JSON_Object *rt = NULL;
+
+	if (!node) {
 		return FALSE;
 	}
@@ -481,10 +487,10 @@
 
 	JSON_O_FOREACH(node, k, v) {
-		if (strcmp("text", k) == 0 && v->type == json_string) {
-			txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1);
+		if (strcmp("text", k) == 0 && (txs->text = g_strdup(json_string(v)))) {
+			// TODO: Huh strip html? In json? Not sure whether I have to..
 			strip_html(txs->text);
-		} else if (strcmp("retweeted_status", k) == 0 && v->type == json_object) {
-			rt = v;
-		} else if (strcmp("created_at", k) == 0 && v->type == json_string) {
+		} else if (strcmp("retweeted_status", k) == 0 && (rt = json_object(v))) {
+			// Handling below.
+		} else if (strcmp("created_at", k) == 0 && json_type(v) == JSONString) {
 			struct tm parsed;
 
@@ -492,13 +498,13 @@
 			   this field. :-( Also assumes the timezone used
 			   is UTC since C time handling functions suck. */
-			if (strptime(v->u.string.ptr, TWITTER_TIME_FORMAT, &parsed) != NULL) {
+			if (strptime(json_string(v), TWITTER_TIME_FORMAT, &parsed) != NULL) {
 				txs->created_at = mktime_utc(&parsed);
 			}
-		} else if (strcmp("user", k) == 0 && v->type == json_object) {
-			txs->user = twitter_xt_get_user(v);
-		} else if (strcmp("id", k) == 0 && v->type == json_integer) {
-			txs->rt_id = txs->id = v->u.integer;
-		} else if (strcmp("in_reply_to_status_id", k) == 0 && v->type == json_integer) {
-			txs->reply_to = v->u.integer;
+		} else if (strcmp("user", k) == 0 && json_type(v) == JSONObject) {
+			txs->user = twitter_xt_get_user(json_object(v));
+		} else if (strcmp("id", k) == 0 && json_type(v) == JSONInteger) {
+			txs->rt_id = txs->id = json_integer(v);
+		} else if (strcmp("in_reply_to_status_id", k) == 0 && json_type(v) == JSONInteger) {
+			txs->reply_to = json_integer(v);
 		}
 	}
@@ -529,9 +535,9 @@
  * Function to fill a twitter_xml_status struct (DM variant).
  */
-static struct twitter_xml_status *twitter_xt_get_dm(const json_value *node)
+static struct twitter_xml_status *twitter_xt_get_dm(const JSON_Object *node)
 {
 	struct twitter_xml_status *txs;
 
-	if (node->type != json_object) {
+	if (!node) {
 		return FALSE;
 	}
@@ -539,8 +545,7 @@
 
 	JSON_O_FOREACH(node, k, v) {
-		if (strcmp("text", k) == 0 && v->type == json_string) {
-			txs->text = g_memdup(v->u.string.ptr, v->u.string.length + 1);
+		if (strcmp("text", k) == 0 && (txs->text = g_strdup(json_string(v)))) {
 			strip_html(txs->text);
-		} else if (strcmp("created_at", k) == 0 && v->type == json_string) {
+		} else if (strcmp("created_at", k) == 0 && json_type(v) == JSONString) {
 			struct tm parsed;
 
@@ -548,11 +553,11 @@
 			   this field. :-( Also assumes the timezone used
 			   is UTC since C time handling functions suck. */
-			if (strptime(v->u.string.ptr, TWITTER_TIME_FORMAT, &parsed) != NULL) {
+			if (strptime(json_string(v), TWITTER_TIME_FORMAT, &parsed) != NULL) {
 				txs->created_at = mktime_utc(&parsed);
 			}
-		} else if (strcmp("sender", k) == 0 && v->type == json_object) {
-			txs->user = twitter_xt_get_user(v);
-		} else if (strcmp("id", k) == 0 && v->type == json_integer) {
-			txs->id = v->u.integer;
+		} else if (strcmp("sender", k) == 0 && json_type(v) == JSONObject) {
+			txs->user = twitter_xt_get_user(json_object(v));
+		} else if (strcmp("id", k) == 0 && json_type(v) == JSONInteger) {
+			txs->id = json_integer(v);
 		}
 	}
@@ -568,12 +573,12 @@
 }
 
-static void expand_entities(char **text, const json_value *node)
-{
-	json_value *entities, *quoted;
+static void expand_entities(char **text, const JSON_Object *node)
+{
+	JSON_Object *entities, *quoted;
 	char *quote_url = NULL, *quote_text = NULL;
 
-	if (!((entities = json_o_get(node, "entities")) && entities->type == json_object))
-		return;
-	if ((quoted = json_o_get(node, "quoted_status")) && quoted->type == json_object) {
+	if (!(entities = json_object_get_object(node, "entities")))
+		return;
+	if ((quoted = json_object_get_object(node, "quoted_status"))) {
 		/* New "retweets with comments" feature. Note that this info
 		 * seems to be included in the streaming API only! Grab the
@@ -591,5 +596,5 @@
 		int i;
 
-		if (v->type != json_array) {
+		if (json_type(v) != JSONArray) {
 			continue;
 		}
@@ -598,14 +603,15 @@
 		}
 
-		for (i = 0; i < v->u.array.length; i++) {
+		for (i = 0; i < json_array_get_count(json_array(v)); i++) {
 			const char *format = "%s%s <%s>%s";
-
-			if (v->u.array.values[i]->type != json_object) {
+			JSON_Object *r = json_array_get_object(json_array(v), i);
+
+			if (!r) {
 				continue;
 			}
 
-			const char *kort = json_o_str(v->u.array.values[i], "url");
-			const char *disp = json_o_str(v->u.array.values[i], "display_url");
-			const char *full = json_o_str(v->u.array.values[i], "expanded_url");
+			const char *kort = json_object_get_string(r, "url");
+			const char *disp = json_object_get_string(r, "display_url");
+			const char *full = json_object_get_string(r, "expanded_url");
 			char *pos, *new;
 
@@ -636,5 +642,5 @@
  *  - the next_cursor.
  */
-static gboolean twitter_xt_get_status_list(struct im_connection *ic, const json_value *node,
+static gboolean twitter_xt_get_status_list(struct im_connection *ic, const JSON_Value *node,
                                            struct twitter_xml_list *txl)
 {
@@ -645,5 +651,5 @@
 	txl->type = TXL_STATUS;
 
-	if (node->type != json_array) {
+	if (json_type(node) != JSONArray) {
 		return FALSE;
 	}
@@ -651,6 +657,6 @@
 	// The root <statuses> node should hold the list of statuses <status>
 	// Walk over the nodes children.
-	for (i = 0; i < node->u.array.length; i++) {
-		txs = twitter_xt_get_status(node->u.array.values[i]);
+	for (i = 0; i < json_array_get_count(json_array(node)); i++) {
+		txs = twitter_xt_get_status(json_array_get_object(json_array(node), i));
 		if (!txs) {
 			continue;
@@ -858,5 +864,5 @@
 }
 
-static gboolean twitter_stream_handle_object(struct im_connection *ic, json_value *o, gboolean from_filter);
+static gboolean twitter_stream_handle_object(struct im_connection *ic, JSON_Object *o, gboolean from_filter);
 
 static void twitter_http_stream(struct http_request *req)
@@ -864,5 +870,5 @@
 	struct im_connection *ic = req->data;
 	struct twitter_data *td;
-	json_value *parsed;
+	JSON_Value *parsed;
 	int len = 0;
 	char c, *nl;
@@ -902,7 +908,7 @@
 		req->reply_body[len] = '\0';
 
-		if ((parsed = json_parse(req->reply_body, req->body_size))) {
+		if ((parsed = json_parse_string(req->reply_body))) {
 			from_filter = (req == td->filter_stream);
-			twitter_stream_handle_object(ic, parsed, from_filter);
+			twitter_stream_handle_object(ic, json_object(parsed), from_filter);
 		}
 		json_value_free(parsed);
@@ -918,12 +924,12 @@
 }
 
-static gboolean twitter_stream_handle_event(struct im_connection *ic, json_value *o);
+static gboolean twitter_stream_handle_event(struct im_connection *ic, JSON_Object *o);
 static gboolean twitter_stream_handle_status(struct im_connection *ic, struct twitter_xml_status *txs);
 
-static gboolean twitter_stream_handle_object(struct im_connection *ic, json_value *o, gboolean from_filter)
+static gboolean twitter_stream_handle_object(struct im_connection *ic, JSON_Object *o, gboolean from_filter)
 {
 	struct twitter_data *td = ic->proto_data;
 	struct twitter_xml_status *txs;
-	json_value *c;
+	JSON_Object *c;
 
 	if ((txs = twitter_xt_get_status(o))) {
@@ -932,5 +938,5 @@
 		txs_free(txs);
 		return ret;
-	} else if ((c = json_o_get(o, "direct_message")) &&
+	} else if ((c = json_object_get_object(o, "direct_message")) &&
 	           (txs = twitter_xt_get_dm(c))) {
 		if (g_strcasecmp(txs->user->screen_name, td->user) != 0) {
@@ -940,12 +946,12 @@
 		txs_free(txs);
 		return TRUE;
-	} else if ((c = json_o_get(o, "event")) && c->type == json_string) {
+	} else if (json_object_get_string(o, "event")) {
 		twitter_stream_handle_event(ic, o);
 		return TRUE;
-	} else if ((c = json_o_get(o, "disconnect")) && c->type == json_object) {
+	} else if ((c = json_object_get_object(o, "disconnect"))) {
 		/* HACK: Because we're inside an event handler, we can't just
 		   disconnect here. Instead, just change the HTTP status string
 		   into a Twitter status string. */
-		char *reason = json_o_strdup(c, "reason");
+		char *reason = g_strdup(json_object_get_string(c, "reason"));
 		if (reason) {
 			g_free(td->stream->status_string);
@@ -986,13 +992,12 @@
 }
 
-static gboolean twitter_stream_handle_event(struct im_connection *ic, json_value *o)
-{
-	struct twitter_data *td = ic->proto_data;
-	json_value *source = json_o_get(o, "source");
-	json_value *target = json_o_get(o, "target");
-	const char *type = json_o_str(o, "event");
-
-	if (!type || !source || source->type != json_object
-	    || !target || target->type != json_object) {
+static gboolean twitter_stream_handle_event(struct im_connection *ic, JSON_Object *o)
+{
+	struct twitter_data *td = ic->proto_data;
+	JSON_Object *source = json_object_get_object(o, "source");
+	JSON_Object *target = json_object_get_object(o, "target");
+	const char *type = json_object_get_string(o, "event");
+
+	if (!type || !source || !target) {
 		return FALSE;
 	}
@@ -1091,7 +1096,5 @@
 	struct twitter_filter *tf;
 	GList *users = NULL;
-	json_value *parsed;
-	json_value *id;
-	const char *name;
+	JSON_Value *parsed;
 	GString *fstr;
 	GSList *l;
@@ -1118,13 +1121,14 @@
 	}
 
-	if (parsed->type != json_array) {
+	if (json_type(parsed) != JSONArray) {
 		goto finish;
 	}
 
-	for (i = 0; i < parsed->u.array.length; i++) {
-		id = json_o_get(parsed->u.array.values[i], "id");
-		name = json_o_str(parsed->u.array.values[i], "screen_name");
-
-		if (!name || !id || id->type != json_integer) {
+	for (i = 0; i < json_array_get_count(json_array(parsed)); i++) {
+		JSON_Object *o = json_array_get_object(json_array(parsed), i);
+		jint id = json_object_get_integer(o, "id");
+		const char *name = json_object_get_string(o, "screen_name");
+
+		if (!name || !id) {
 			continue;
 		}
@@ -1134,5 +1138,5 @@
 
 			if (g_strcasecmp(tf->text, name) == 0) {
-				tf->uid = id->u.integer;
+				tf->uid = id;
 				users = g_list_delete_link(users, u);
 				break;
@@ -1375,5 +1379,5 @@
 	struct im_connection *ic = req->data;
 	struct twitter_data *td;
-	json_value *parsed;
+	JSON_Value *parsed;
 	struct twitter_xml_list *txl;
 
@@ -1414,5 +1418,5 @@
 	struct im_connection *ic = req->data;
 	struct twitter_data *td;
-	json_value *parsed;
+	JSON_Value *parsed;
 	struct twitter_xml_list *txl;
 
@@ -1454,5 +1458,6 @@
 	struct im_connection *ic = req->data;
 	struct twitter_data *td;
-	json_value *parsed, *id;
+	JSON_Value *parsed;
+	jint id;
 
 	// Check if the connection is still active.
@@ -1468,6 +1473,6 @@
 	}
 
-	if ((id = json_o_get(parsed, "id")) && id->type == json_integer) {
-		td->last_status_id = id->u.integer;
+	if ((id = json_object_get_integer(json_object(parsed), "id"))) {
+		td->last_status_id = id;
 	}
 
@@ -1577,5 +1582,6 @@
 {
 	struct im_connection *ic = req->data;
-	json_value *parsed, *id;
+	JSON_Value *parsed;
+	uint64_t id;
 	const char *name;
 
@@ -1589,14 +1595,9 @@
 	}
 
-	/* for the parson branch:
 	name = json_object_dotget_string(json_object(parsed), "user.screen_name");
 	id = json_object_get_integer(json_object(parsed), "id");
-	*/
-
-	name = json_o_str(json_o_get(parsed, "user"), "screen_name");
-	id = json_o_get(parsed, "id");
-
-	if (name && id && id->type == json_integer) {
-		twitter_log(ic, "https://twitter.com/%s/status/%" G_GUINT64_FORMAT, name, id->u.integer);
+
+	if (name && id) {
+		twitter_log(ic, "https://twitter.com/%s/status/%" G_GUINT64_FORMAT, name, id);
 	} else {
 		twitter_log(ic, "Error: could not fetch tweet url.");
