json.builder.Builder provides an object for generating a JSON tree.
The root of the JSON tree can be either a json.object.ObjectJson or a json.array.Array. Thus the first call must necessarily be either json.builder.Builder.beginObject or json.builder.Builder.beginArray.
For convenience to language bindings, most json.builder.Builder method return the instance, making it easy to chain function calls.
g_autoptr(JsonBuilder) builder = json_builder_new (); json_builder_begin_object (builder); json_builder_set_member_name (builder, "url"); json_builder_add_string_value (builder, "http://www.gnome.org/img/flash/two-thirty.png"); json_builder_set_member_name (builder, "size"); json_builder_begin_array (builder); json_builder_add_int_value (builder, 652); json_builder_add_int_value (builder, 242); json_builder_end_array (builder); json_builder_end_object (builder); g_autoptr(JsonNode) root = json_builder_get_root (builder); g_autoptr(JsonGenerator) gen = json_generator_new (); json_generator_set_root (gen, root); g_autofree char *str = json_generator_to_data (gen, NULL); // str now contains the following JSON data // { "url" : "http://www.gnome.org/img/flash/two-thirty.png", "size" : [ 652, 242 ] }
json.builder.Builder provides an object for generating a JSON tree.
The root of the JSON tree can be either a json.object.ObjectJson or a json.array.Array. Thus the first call must necessarily be either json.builder.Builder.beginObject or json.builder.Builder.beginArray.
For convenience to language bindings, most json.builder.Builder method return the instance, making it easy to chain function calls.
Using json.builder.Builder