char * json_value_to_string (json_value_t *self) { switch (self->type) { case JSON_TYPE_GENERIC: return (char *) self->data; case JSON_TYPE_BOOLEAN: return json_boolean_to_string((json_boolean_t *) self); case JSON_TYPE_NULL: return json_null_to_string((json_null_t *) self); case JSON_TYPE_NUMBER: return json_number_to_string((json_number_t *) self); case JSON_TYPE_STRING: return json_string_to_string((json_string_t *) self); case JSON_TYPE_OBJECT: return json_object_to_string((json_object_t *) self); case JSON_TYPE_ARRAY: return json_array_to_string((json_array_t *) self); } return NULL; }
strbuffer_t * json_to_string(json_t* object) { strbuffer_t* sb = strbuffer_new(); strbuffer_t* tempString; if(object == NULL) { strbuffer_append(sb, ""); return sb; } switch(object->type) { case JSON_OBJECT: tempString = json_object_to_string(object); strbuffer_append(sb, tempString->value); strbuffer_destroy(tempString); break; case JSON_ARRAY: tempString = json_array_to_string(object); strbuffer_append(sb, tempString->value); strbuffer_destroy(tempString); break; case JSON_STRING: strbuffer_append(sb, "\"" ); strbuffer_append(sb, object->value ); strbuffer_append(sb, "\"" ); break; case JSON_NUMBER: strbuffer_append(sb, object->value); break; case JSON_TRUE: strbuffer_append(sb, "true"); break; case JSON_FALSE: strbuffer_append(sb, "false"); break; case JSON_NULL: strbuffer_append(sb, "null"); break; default: break; } return sb; }