Json.Generator¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
Number of indentation spaces |
||
r/w |
Character that should be used when indenting |
||
r/w |
Pretty-print the output |
||
r/w |
Root of the JSON data tree |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Json.Generator(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
JsonGenerator
provides an object for generating a JSON data stream from a tree of [struct`Json`.Node] instances, and put it into a buffer or a file.- classmethod new()¶
- Returns:
the newly created generator instance
- Return type:
Creates a new
JsonGenerator
.You can use this object to generate a JSON data stream starting from a data object model composed by [struct`Json`.Node]s.
- get_indent()¶
- Returns:
the number of repetitions per indentation level
- Return type:
Retrieves the value set using [method`Json`.Generator.set_indent].
New in version 0.14.
- get_indent_char()¶
- Returns:
the character to be used when indenting
- Return type:
Retrieves the value set using [method`Json`.Generator.set_indent_char].
New in version 0.14.
- get_pretty()¶
- Returns:
TRUE
if the generated JSON should be pretty-printed, andFALSE
otherwise- Return type:
Retrieves the value set using [method`Json`.Generator.set_pretty].
New in version 0.14.
- get_root()¶
-
Retrieves a pointer to the root node set using [method`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.
Pretty printing will use indentation character specified in the [property`Json`.Generator:indent-char] property and the spacing specified in the [property`Json`.Generator:indent] property.
New in version 0.14.
- set_root(node)¶
- Parameters:
node (
Json.Node
) – the root node
Sets the root of the JSON data stream to be serialized by the given 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 string holding a JSON data stream
- length:
return location for the length of the returned buffer
- Return type:
Generates a JSON data stream from self and returns it as a buffer.
- to_file(filename)¶
- Parameters:
filename (
str
) – the path to the target file- Raises:
- Returns:
True
if saving was successful.- Return type:
Creates a JSON data stream and puts it inside
filename
, overwriting the file’s current contents.This operation is atomic, in the sense that the data is written to a temporary file which is then renamed to the given
filename
.
- to_gstring(string)¶
- Parameters:
string (
GLib.String
) – a string buffer- Returns:
the passed string, updated with the generated JSON data
- Return type:
Generates a JSON data stream and appends it to the string buffer.
New in version 1.4.
- to_stream(stream, cancellable)¶
- Parameters:
stream (
Gio.OutputStream
) – the output stream used to write the JSON datacancellable (
Gio.Cancellable
orNone
) – aGCancellable
- Raises:
- Returns:
whether the write operation was successful
- Return type:
Outputs JSON data and writes it (synchronously) to the given stream.
New in version 0.12.
Property Details¶
- Json.Generator.props.indent¶
-
Number of spaces to be used to indent when pretty printing.
- Json.Generator.props.indent_char¶
-
The character that should be used when indenting in pretty print.
New in version 0.6.
- Json.Generator.props.pretty¶
-
Whether the output should be “pretty-printed”, with indentation and newlines.
The indentation level can be controlled by using the [property`Json`.Generator:indent] property.