Json.Generator¶
| Subclasses: | None | 
|---|
Methods¶
| Inherited: | GObject.Object (37) | 
|---|---|
| Structs: | GObject.ObjectClass (5) | 
| class | new() | 
| get_indent() | |
| get_indent_char() | |
| get_pretty() | |
| get_root() | |
| set_indent(indent_level) | |
| set_indent_char(indent_char) | |
| set_pretty(is_pretty) | |
| set_root(node) | |
| to_data() | |
| to_file(filename) | |
| to_gstring(string) | |
| to_stream(stream, cancellable) | 
Virtual Methods¶
| Inherited: | GObject.Object (7) | 
|---|
Properties¶
| Name | Type | Flags | Short Description | 
|---|---|---|---|
| indent | int | r/w | Number of indentation spaces | 
| indent-char | int | r/w | Character that should be used when indenting | 
| pretty | bool | r/w | Pretty-print the output | 
| root | Json.Node | r/w | Root of the JSON data tree | 
Signals¶
| Inherited: | GObject.Object (1) | 
|---|
Class Details¶
- 
class Json.Generator(**kwargs)¶
- Bases: - GObject.Object- Abstract: - No - Structure: - Json.GeneratorClass- JSON data streams generator. The contents of the - Json.Generatorstructure are private and should only be accessed via the provided API.- 
classmethod new()¶
- Returns: - the newly created - Json.Generatorinstance- Return type: - Json.Generator- Creates a new - Json.Generator. You can use this object to generate a JSON data stream starting from a data object model composed by- Json.Nodes.
 - 
get_indent()¶
- Returns: - the number of repetitions per indentation level - Return type: - int- Retrieves the value set using - Json.Generator.set_indent().- New in version 0.14. 
 - 
get_indent_char()¶
- Returns: - the character to be used when indenting - Return type: - str- Retrieves the value set using - Json.Generator.set_indent_char().- New in version 0.14. 
 - 
get_pretty()¶
- Returns: - Trueif the generated JSON should be pretty-printed, and- Falseotherwise- Return type: - bool- Retrieves the value set using - Json.Generator.set_pretty().- New in version 0.14. 
 - 
get_root()¶
- Returns: - a - Json.Node, or- None. The returned node is owned by the- Json.Generatorand it should not be freed- Return type: - Json.Nodeor- None- Retrieves a pointer to the root - Json.Nodeset using- Json.Generator.set_root().- New in version 0.14. 
 - 
set_indent(indent_level)¶
- Parameters: - indent_level ( - int) – the number of repetitions of the indentation character that should be applied when pretty printing- Sets the number of repetitions for each indentation level. - New in version 0.14. 
 - 
set_indent_char(indent_char)¶
- Parameters: - indent_char ( - str) – a Unicode character to be used when indenting- Sets the character to be used when indenting - New in version 0.14. 
 - 
set_pretty(is_pretty)¶
- Parameters: - is_pretty ( - bool) – whether the generated string should be pretty printed- Sets whether the generated JSON should be pretty printed, using the indentation character specified in the - Json.Generator- :indent-charproperty and the spacing specified in- Json.Generator- :indentproperty.- New in version 0.14. 
 - 
set_root(node)¶
- Parameters: - node ( - Json.Node) – a- Json.Node- Sets node as the root of the JSON data stream to be serialized by the - Json.Generator.- The passed node is copied by the generator object, so it can be safely freed after calling this function. 
 - 
to_data()¶
- Returns: - a newly allocated buffer holding a JSON data stream. Use - GLib.free() to free the allocated resources.- length: - return location for the length of the returned buffer, or - None- Return type: - ( - str, length:- int)- Generates a JSON data stream from self and returns it as a buffer. 
 - 
to_file(filename)¶
- Parameters: - filename ( - str) – path to the target file- Raises: - GLib.Error- Returns: - Trueif saving was successful.- Return type: - bool- Creates a JSON data stream and puts it inside filename, overwriting the current file contents. This operation is atomic. 
 - 
to_gstring(string)¶
- Parameters: - string ( - GLib.String) – a- GLib.String- Returns: - a - GLib.Stringholding a JSON data stream. Use- GLib.String.free() to free the allocated resources.- Return type: - GLib.String- Generates a JSON data stream from self and appends it to string. - New in version 1.4. 
 - 
to_stream(stream, cancellable)¶
- Parameters: - stream (Gio.OutputStream) – aGio.OutputStream
- cancellable (Gio.CancellableorNone) – aGio.Cancellable, orNone
 - Raises: - Returns: - Trueif the write operation was successful, and- Falseon failure. In case of error, the- GLib.Errorwill be filled accordingly- Return type: - Outputs JSON data and streams it (synchronously) to stream. - New in version 0.12. 
- stream (
 
- 
classmethod 
Property Details¶
- 
Json.Generator.props.indent¶
- Name: - indent- Type: - int- Default Value: - 2- Flags: - READABLE,- WRITABLE- Number of spaces to be used to indent when pretty printing. 
- 
Json.Generator.props.indent_char¶
- Name: - indent-char- Type: - int- Default Value: - 32- Flags: - READABLE,- WRITABLE- The character that should be used when indenting in pretty print. - New in version 0.6.