Json.Builder

g GObject.Object GObject.Object Json.Builder Json.Builder GObject.Object->Json.Builder

Subclasses:None

Methods

Inherited:GObject.Object (37)
Structs:GObject.ObjectClass (5)
class new ()
class new_immutable ()
  add_boolean_value (value)
  add_double_value (value)
  add_int_value (value)
  add_null_value ()
  add_string_value (value)
  add_value (node)
  begin_array ()
  begin_object ()
  end_array ()
  end_object ()
  get_root ()
  reset ()
  set_member_name (member_name)

Virtual Methods

Inherited:GObject.Object (7)

Properties

Name Type Flags Short Description
immutable bool r/w/co Whether the builder output is immutable.

Signals

Inherited:GObject.Object (1)

Fields

Inherited:GObject.Object (1)
Name Type Access Description
parent_instance GObject.Object r  

Class Details

class Json.Builder(**kwargs)
Bases:GObject.Object
Abstract:No
Structure:Json.BuilderClass

The JsonBuilder structure contains only private data and should be accessed using the provided API

New in version 0.12.

classmethod new()
Returns:the newly created Json.Builder instance
Return type:Json.Builder

Creates a new Json.Builder. You can use this object to generate a JSON tree and obtain the root Json.Node.

classmethod new_immutable()
Returns:a new Json.Builder
Return type:Json.Builder

Creates a new Json.Builder instance with its Json.Builder :immutable property set to True to create immutable output trees.

New in version 1.2.

add_boolean_value(value)
Parameters:value (bool) – the value of the member or element
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

If called after Json.Builder.set_member_name(), sets value as member of the most recent opened object, otherwise value is added as element of the most recent opened array.

See also: Json.Builder.add_value()

add_double_value(value)
Parameters:value (float) – the value of the member or element
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

If called after Json.Builder.set_member_name(), sets value as member of the most recent opened object, otherwise value is added as element of the most recent opened array.

See also: Json.Builder.add_value()

add_int_value(value)
Parameters:value (int) – the value of the member or element
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

If called after Json.Builder.set_member_name(), sets value as member of the most recent opened object, otherwise value is added as element of the most recent opened array.

See also: Json.Builder.add_value()

add_null_value()
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

If called after Json.Builder.set_member_name(), sets null as member of the most recent opened object, otherwise null is added as element of the most recent opened array.

See also: Json.Builder.add_value()

add_string_value(value)
Parameters:value (str) – the value of the member or element
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

If called after Json.Builder.set_member_name(), sets value as member of the most recent opened object, otherwise value is added as element of the most recent opened array.

See also: Json.Builder.add_value()

add_value(node)
Parameters:node (Json.Node) – the value of the member or element
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

If called after Json.Builder.set_member_name(), sets node as member of the most recent opened object, otherwise node is added as element of the most recent opened array.

The builder will take ownership of the Json.Node.

begin_array()
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

Opens a subarray inside the given self. When done adding members to the subarray, Json.Builder.end_array() must be called.

Can be called for first or only if the call is associated to an object member or an array element.

begin_object()
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

Opens a subobject inside the given self. When done adding members to the subobject, Json.Builder.end_object() must be called.

Can be called for first or only if the call is associated to an object member or an array element.

end_array()
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

Closes the subarray inside the given self that was opened by the most recent call to Json.Builder.begin_array().

Cannot be called after Json.Builder.set_member_name().

end_object()
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

Closes the subobject inside the given self that was opened by the most recent call to Json.Builder.begin_object().

Cannot be called after Json.Builder.set_member_name().

get_root()
Returns:the Json.Node, or None if the build is not complete. Free the returned value with Json.Node.unref().
Return type:Json.Node or None

Returns the root of the current constructed tree, if the build is complete (ie: all opened objects, object members and arrays are being closed).

reset()

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

set_member_name(member_name)
Parameters:member_name (str) – the name of the member
Returns:the Json.Builder, or None if the call was inconsistent
Return type:Json.Builder or None

Set the name of the next member in an object. The next call must add a value, open an object or an array.

Can be called only if the call is associated to an object.

Property Details

Json.Builder.props.immutable
Name:immutable
Type:bool
Default Value:False
Flags:READABLE, WRITABLE, CONSTRUCT_ONLY

Whether the Json.Node tree built by the Json.Builder should be immutable when created. Making the output immutable on creation avoids the expense of traversing it to make it immutable later.

New in version 1.2.