61 lines
1.4 KiB
C
61 lines
1.4 KiB
C
#include "rjp.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
RJP_value* do_object(void){
|
|
RJP_value* obj = rjp_new_object();
|
|
RJP_value* mem = rjp_new_member_key_copy(obj, "key", 0);
|
|
rjp_set_int(mem, 10);
|
|
return obj;
|
|
}
|
|
RJP_value* do_ordered_object(void){
|
|
RJP_value* obj = rjp_new_ordered_object();
|
|
RJP_value* mem = rjp_new_member_key_copy(obj, "key", 0);
|
|
rjp_set_int(mem, 10);
|
|
return obj;
|
|
}
|
|
RJP_value* do_array(void){
|
|
RJP_value* arr = rjp_new_array();
|
|
RJP_value* elm = rjp_new_element(arr);
|
|
rjp_set_int(elm, 10);
|
|
return arr;
|
|
}
|
|
RJP_value* do_string(void){
|
|
RJP_value* str = rjp_new_string_copy("str", 0);
|
|
return str;
|
|
}
|
|
RJP_value* do_integer(void){
|
|
return rjp_new_int(5);
|
|
}
|
|
RJP_value* do_dfloat(void){
|
|
return rjp_new_float(5);
|
|
}
|
|
RJP_value* do_boolean(void){
|
|
return rjp_new_bool(1);
|
|
}
|
|
RJP_value* do_null(void){
|
|
return rjp_new_null();
|
|
}
|
|
|
|
int main(){
|
|
RJP_value* obj = do_object();
|
|
RJP_value* arr = rjp_add_member_key_copy(obj, "key2", 0, do_array());
|
|
rjp_add_element(arr, do_string());
|
|
rjp_add_element(arr, do_integer());
|
|
rjp_add_element(arr, do_dfloat());
|
|
rjp_add_element(arr, do_boolean());
|
|
rjp_add_member_key_copy(obj, "an-in-order", 0, do_integer());
|
|
|
|
char* buf = rjp_to_json(obj, RJP_FORMAT_PRETTY);
|
|
printf("%s\n", buf);
|
|
rjp_free(buf);
|
|
|
|
rjp_object_to_ordered(obj);
|
|
rjp_add_member_key_copy(obj, "an-out-of-order", 0, do_integer());
|
|
buf = rjp_to_json(obj, RJP_FORMAT_PRETTY);
|
|
printf("%s\n", buf);
|
|
rjp_free(buf);
|
|
|
|
rjp_free_value(obj);
|
|
}
|