Fwupd.JsonObject

Fields

None

Methods

add_array (key, json_arr)

add_array_strv (key, value)

add_boolean (key, value)

add_bytes (key, value)

add_integer (key, value)

add_node (key, json_node)

add_object (key, json_obj)

add_object_map (key, value)

add_raw (key, value)

add_string (key, value)

clear ()

get_boolean (key)

get_boolean_with_default (key, value_default)

get_integer (key)

get_integer_with_default (key, value_default)

get_size ()

get_string_with_default (key, value_default)

to_bytes (flags)

to_string (flags)

Details

class Fwupd.JsonObject

A JSON object.

See also: ‘struct@FwupdJsonArray [struct@FwupdJsonNode]’

add_array(key, json_arr)[source]
Parameters:

Adds an array to the JSON object.

New in version 2.1.1.

add_array_strv(key, value)[source]
Parameters:
  • key (str) – dictionary key

  • value (str) – value

Adds a string array to the JSON object. If the node already exists the old one is replaced.

New in version 2.1.1.

add_boolean(key, value)[source]
Parameters:
  • key (str) – dictionary key

  • value (bool) – boolean

Adds a boolean value to the JSON object.

New in version 2.1.1.

add_bytes(key, value)[source]
Parameters:

Adds bytes to the JSON object. They will be base64 encoded as a string. If the node already exists the old one is replaced.

New in version 2.1.1.

add_integer(key, value)[source]
Parameters:
  • key (str) – dictionary key

  • value (int) – integer

Adds an integer value to the JSON object.

New in version 2.1.1.

add_node(key, json_node)[source]
Parameters:

Adds a node to the JSON object. If the node already exists the old one is replaced.

New in version 2.1.1.

add_object(key, json_obj)[source]
Parameters:

Adds a different object to the JSON object.

New in version 2.1.1.

add_object_map(key, value)[source]
Parameters:
  • key (str) – dictionary key

  • value ({str: str}) – a hash table

Adds a object to the JSON object.

New in version 2.1.1.

add_raw(key, value)[source]
Parameters:
  • key (str) – dictionary key

  • value (str) – value

Adds a raw value to the JSON object. If the node already exists the old one is replaced.

New in version 2.1.1.

add_string(key, value)[source]
Parameters:

Adds a string value to the JSON object. If the node already exists the old one is replaced.

New in version 2.1.1.

clear()[source]

Clears the member data for the JSON object, but does not affect the refcount.

New in version 2.1.1.

get_boolean(key)[source]
Parameters:

key (str) – dictionary key

Raises:

GLib.Error

Returns:

True if value was parsed as an integer

value:

boolean value

Return type:

(bool, value: bool)

Gets a boolean from a JSON object. An error is returned if key is not the correct type.

New in version 2.1.1.

get_boolean_with_default(key, value_default)[source]
Parameters:
  • key (str) – dictionary key

  • value_default (bool) – value to return if key is not found, typically False

Raises:

GLib.Error

Returns:

True if value was parsed as an integer

value:

boolean value

Return type:

(bool, value: bool)

Gets a boolean from a JSON object. An error is returned if key is not the correct type.

New in version 2.1.1.

get_integer(key)[source]
Parameters:

key (str) – dictionary key

Raises:

GLib.Error

Returns:

True if value was parsed as an integer

value:

integer value

Return type:

(bool, value: int)

Gets an integer from a JSON object. An error is returned if key is not the correct type.

New in version 2.1.1.

get_integer_with_default(key, value_default)[source]
Parameters:
  • key (str) – dictionary key

  • value_default (int) – value to return if key is not found, typically 0 or GObject.G_MAXINT64

Raises:

GLib.Error

Returns:

True if value was parsed as an integer

value:

integer value

Return type:

(bool, value: int)

Gets an integer from a JSON object. An error is returned if key is not the correct type.

New in version 2.1.1.

get_size()[source]
Returns:

number of key-values added

Return type:

int

Gets the size of the JSON object.

New in version 2.1.1.

get_string_with_default(key, value_default)[source]
Parameters:
  • key (str) – dictionary key

  • value_default (str) – value to return if key is not found

Raises:

GLib.Error

Returns:

a string, or None on error

Return type:

str

Gets a string from a JSON object. An error is returned if key is not the correct type.

New in version 2.1.1.

to_bytes(flags)[source]
Parameters:

flags (Fwupd.JsonExportFlags) – some Fwupd.JsonExportFlags e.g. Fwupd.JsonExportFlags.INDENT

Returns:

a GLib.Bytes

Return type:

GLib.Bytes

Converts the JSON object to UTF-8 bytes.

New in version 2.1.1.

to_string(flags)[source]
Parameters:

flags (Fwupd.JsonExportFlags) – some Fwupd.JsonExportFlags e.g. Fwupd.JsonExportFlags.INDENT

Returns:

a GLib.String

Return type:

GLib.String

Converts the JSON object to a string representation.

New in version 2.1.1.