Json.Builder
Description: Reference for Json.Builder

### Class

# JsonBuilder

#### Description [src]

    class Json.Builder : GObject.Object
    {
      /* No available fields */
    }

`JsonBuilder` provides an object for generating a JSON tree.

The root of the JSON tree can be either a `JsonObject` or a `JsonArray`. Thus the first call must necessarily be either `json_builder_begin_object()` or `json_builder_begin_array()`.

For convenience to language bindings, most `JsonBuilder` method return the instance, making it easy to chain function calls.

## Using `JsonBuilder`

    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 ] }

#### Ancestors

- GObject

#### Constructors

###### json_builder_new

Creates a new `JsonBuilder`.

###### json_builder_new_immutable

Creates a new, immutable `JsonBuilder` instance.

since: 1.2

#### Instance methods

###### json_builder_add_boolean_value

Adds a boolean value to the currently open object member or array.

###### json_builder_add_double_value

Adds a floating point value to the currently open object member or array.

###### json_builder_add_int_value

Adds an integer value to the currently open object member or array.

###### json_builder_add_null_value

Adds a null value to the currently open object member or array.

###### json_builder_add_string_value

Adds a string value to the currently open object member or array.

###### json_builder_add_value

Adds a value to the currently open object member or array.

###### json_builder_begin_array

Opens an array inside the given builder.

###### json_builder_begin_object

Opens an object inside the given builder.

###### json_builder_end_array

Closes the array inside the given builder that was opened by the most recent call to `json_builder_begin_array()`.

###### json_builder_end_object

Closes the object inside the given builder that was opened by the most recent call to `json_builder_begin_object()`.

###### json_builder_get_root

Returns the root of the currently constructed tree.

###### json_builder_reset

Resets the state of the builder back to its initial state.

###### json_builder_set_member_name

Sets the name of the member in an object.

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### Json.Builder:immutable

Whether the tree should be immutable when created.

since: 1.2

#### Signals

##### Signals inherited from GObject (1)

###### GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

#### Class structure

    struct JsonBuilderClass {
      void (* _json_reserved1) (
    void
      );
      void (* _json_reserved2) (
    void
      );

    }

No description available.

###### Class members

`_json_reserved1: void (* _json_reserved1) ( void )`

  No description available.

`_json_reserved2: void (* _json_reserved2) ( void )`

  No description available.