Spa Json

digraph inheritance { rankdir=LR; GBoxed -> WpSpaJson; GBoxed -> WpSpaJsonBuilder; GBoxed -> WpSpaJsonParser; }

struct WpSpaJson

Since

0.4.8

struct WpSpaJsonBuilder

Since

0.4.8

struct WpSpaJsonParser

Since

0.4.8

WpSpaJson* wp_spa_json_ref(WpSpaJson * self)

Increases the reference count of a spa json object.

Return

(transfer full): self with an additional reference count on it

Parameters
  • self: a spa json object

void wp_spa_json_unref(WpSpaJson * self)

Decreases the reference count on self and frees it when the ref count reaches zero.

Parameters
  • self: (transfer full): a spa json object

WpSpaJson* wp_spa_json_new_from_string(const gchar * json_str)

Constructs a new WpSpaJson from a JSON string.

Return

a new WpSpaJson; unlike the “wrap” variants, this function copies the data in json_str, so it does not need to stay alive.

Since

0.5.0

Parameters
  • json_str: a JSON string

WpSpaJson* wp_spa_json_new_from_stringn(const gchar * json_str, size_t len)

Constructs a new WpSpaJson from a JSON string with specific length.

Return

a new WpSpaJson; unlike the “wrap” variants, this function copies the data in json_str, so it does not need to stay alive.

Since

0.5.0

Parameters
  • json_str: a JSON string

  • len: the specific length of the string

WpSpaJson* wp_spa_json_new_wrap_string(const gchar * json_str)

Constructs a new WpSpaJson that wraps a JSON string.

Return

a new WpSpaJson that references the data in json_str. json_str is not copied, so it needs to stay alive.

Since

0.5.0

Parameters
  • json_str: a JSON string

WpSpaJson* wp_spa_json_new_wrap_stringn(const gchar * json_str, size_t len)

Constructs a new WpSpaJson that wraps a JSON string with specific length.

Return

a new WpSpaJson that references the data in json_str. json_str is not copied, so it needs to stay alive.

Since

0.5.0

Parameters
  • json_str: a JSON string

  • len: the specific length of the string

WpSpaJson* wp_spa_json_new_wrap(struct spa_json * json)

Constructs a new WpSpaJson that wraps the given spa_json.

Return

a new WpSpaJson that references the data in json. json is not copied, so it needs to stay alive.

Parameters
  • json: a spa_json

const struct spa_json* wp_spa_json_get_spa_json(const WpSpaJson * self)

Converts a WpSpaJson pointer to a struct spa_json one, for use with native pipewire & spa functions. The returned pointer is owned by WpSpaJson and may not be modified or freed.

Return

a const pointer to the underlying spa_json structure

Parameters
  • self: a spa json object

const gchar* wp_spa_json_get_data(const WpSpaJson * self)

Returns the json data.

Return

a const pointer to the json data

Parameters
  • self: a spa json object

size_t wp_spa_json_get_size(const WpSpaJson * self)

Returns the json data size.

Return

the json data size

Parameters
  • self: a spa json object

gchar* wp_spa_json_to_string(const WpSpaJson * self)

Returns a newly allocated json string with length matching the size.

Return

(transfer full): the json string with length matching the size

Since

0.4.11

Parameters
  • self: a spa json object

WpSpaJson* wp_spa_json_copy(WpSpaJson * other)

Copies a spa json object.

Return

(transfer full): The newly copied spa json

Parameters
  • other: a spa json object

gboolean wp_spa_json_is_unique_owner(WpSpaJson * self)

Checks if the json is the unique owner of its data or not.

Return

TRUE if the json owns the data, FALSE otherwise.

Parameters
  • self: a spa json object

WpSpaJson* wp_spa_json_ensure_unique_owner(WpSpaJson * self)

If self is not uniquely owned already, then it is unrefed and a copy of it is returned instead. You should always consider self as unsafe to use after this call and you should use the returned object instead.

Return

(transfer full): the uniquely owned spa json object which may or may not be the same as self.

Parameters
  • self: (transfer full): a spa json object

WpSpaJson* wp_spa_json_new_null(void)

Creates a spa json of type NULL.

Return

(transfer full): The new spa json

WpSpaJson* wp_spa_json_new_boolean(gboolean value)

Creates a spa json of type boolean.

Return

(transfer full): The new spa json

Parameters
  • value: the boolean value

WpSpaJson* wp_spa_json_new_int(gint value)

Creates a spa json of type int.

Return

(transfer full): The new spa json

Parameters
  • value: the int value

WpSpaJson* wp_spa_json_new_float(float value)

Creates a spa json of type float.

Return

(transfer full): The new spa json

Parameters
  • value: the float value

WpSpaJson* wp_spa_json_new_string(const gchar * value)

Creates a spa json of type string.

Return

(transfer full): The new spa json

Parameters
  • value: the string value

WpSpaJson* wp_spa_json_new_array(const gchar * format, ...)

Creates a spa json of type array.

Return

(transfer full): The new spa json

Parameters
  • format: (nullable): the first value format (“n”, “b”, “i”, “f”, “s” or “J”)

  • ...: a list of array types and values, followed by NULL

WpSpaJson* wp_spa_json_new_array_valist(const gchar * format, va_list args)

This is the va_list version of wp_spa_json_new_array()

Return

(transfer full): The new spa json

Parameters
  • format: (nullable): the first value format (“n”, “b”, “i”, “f”, “s” or “J”)

  • args: the variable arguments passed to wp_spa_json_new_array()

WpSpaJson* wp_spa_json_new_object(const gchar * key, const gchar * format, ...)

Creates a spa json of type object.

Return

(transfer full): The new spa json

Parameters
  • key: (nullable): the first object property key

  • format: (nullable): the first property format (“n”, “b”, “i”, “f”, “s” or “J”)

  • ...: a list of object properties and values, followed by NULL

WpSpaJson* wp_spa_json_new_object_valist(const gchar * key, const gchar * format, va_list args)

This is the va_list version of wp_spa_json_new_object()

Return

(transfer full): The new spa json

Parameters
  • key: (nullable): the first object property key

  • format: (nullable): the first property format (“n”, “b”, “i”, “f”, “s” or “J”)

  • args: the variable arguments passed to wp_spa_json_new_object()

gboolean wp_spa_json_is_null(WpSpaJson * self)

Checks whether the spa json is of type null or not.

Return

TRUE if it is of type null, FALSE otherwise

Parameters
  • self: the spa json object

gboolean wp_spa_json_is_boolean(WpSpaJson * self)

Checks whether the spa json is of type boolean or not.

Return

TRUE if it is of type boolean, FALSE otherwise

Parameters
  • self: the spa json object

gboolean wp_spa_json_is_int(WpSpaJson * self)

Checks whether the spa json is of type int or not.

Return

TRUE if it is of type int, FALSE otherwise

Parameters
  • self: the spa json object

gboolean wp_spa_json_is_float(WpSpaJson * self)

Checks whether the spa json is of type float or not.

Return

TRUE if it is of type float, FALSE otherwise

Parameters
  • self: the spa json object

gboolean wp_spa_json_is_string(WpSpaJson * self)

Checks whether the spa json is of type string or not.

Return

TRUE if it is of type string, FALSE otherwise

Parameters
  • self: the spa json object

gboolean wp_spa_json_is_array(WpSpaJson * self)

Checks whether the spa json is of type array or not.

Return

TRUE if it is of type array, FALSE otherwise

Parameters
  • self: the spa json object

gboolean wp_spa_json_is_container(WpSpaJson * self)

Checks whether the spa json is of type container or not.

Return

TRUE if it is of type container, FALSE otherwise

Parameters
  • self: the spa json object

gboolean wp_spa_json_is_object(WpSpaJson * self)

Checks whether the spa json is of type object or not.

Return

TRUE if it is of type object, FALSE otherwise

Parameters
  • self: the spa json object

gboolean wp_spa_json_parse_boolean(WpSpaJson * self, gboolean * value)

Parses the boolean value of a spa json object.

Return

TRUE if the value was obtained, FALSE otherwise

Parameters
  • self: the spa json object

  • value: (out): the boolean value

gboolean wp_spa_json_parse_int(WpSpaJson * self, gint * value)

Parses the int value of a spa json object.

Return

TRUE if the value was obtained, FALSE otherwise

Parameters
  • self: the spa json object

  • value: (out): the int value

gboolean wp_spa_json_parse_float(WpSpaJson * self, float * value)

Parses the float value of a spa json object.

Return

TRUE if the value was obtained, FALSE otherwise

Parameters
  • self: the spa json object

  • value: (out): the float value

gchar* wp_spa_json_parse_string(WpSpaJson * self)

Parses the string value of a spa json object.

Return

(transfer full): The newly allocated parsed string

Parameters
  • self: the spa json object

gboolean wp_spa_json_parse_array(WpSpaJson * self, ...)

Parses the array types and values of a spa json object.

Return

TRUE if the types and values were obtained, FALSE otherwise

Parameters
  • self: the spa json object

  • ...: (out): the list of array types and values, followed by NULL

gboolean wp_spa_json_parse_array_valist(WpSpaJson * self, va_list args)

This is the va_list version of wp_spa_json_parse_array()

Return

TRUE if the types and values were obtained, FALSE otherwise

Parameters

gboolean wp_spa_json_parse_object(WpSpaJson * self, ...)

Parses the object properties and values of a spa json object.

Return

TRUE if the properties and values were obtained, FALSE otherwise

Parameters
  • self: the spa json object

  • ...: (out): the list of object properties and values, followed by NULL

gboolean wp_spa_json_parse_object_valist(WpSpaJson * self, va_list args)

This is the va_list version of wp_spa_json_parse_object()

Return

TRUE if the properties and values were obtained, FALSE otherwise

Parameters

gboolean wp_spa_json_object_get(WpSpaJson * self, ...)

Parses the object property values of a spa json object.

Return

TRUE if the properties and values were obtained, FALSE otherwise

Parameters
  • self: the spa json object

  • ...: the list of property names, formats and values, followed by NULL

gboolean wp_spa_json_object_get_valist(WpSpaJson * self, va_list args)

This is the va_list version of wp_spa_json_object_get()

Return

TRUE if the properties and values were obtained, FALSE otherwise

Parameters

WpSpaJsonBuilder* wp_spa_json_builder_ref(WpSpaJsonBuilder * self)

Increases the reference count of a spa json builder.

Return

(transfer full): self with an additional reference count on it

Parameters
  • self: a spa json builder object

void wp_spa_json_builder_unref(WpSpaJsonBuilder * self)

Decreases the reference count on self and frees it when the ref count reaches zero.

Parameters
  • self: (transfer full): a spa json builder object

WpSpaJsonBuilder* wp_spa_json_builder_new_array(void)

Creates a spa json builder of type array.

Return

(transfer full): the new spa json builder

WpSpaJsonBuilder* wp_spa_json_builder_new_object(void)

Creates a spa json builder of type object.

Return

(transfer full): the new spa json builder

void wp_spa_json_builder_add_property(WpSpaJsonBuilder * self, const gchar * key)

Adds a property into the builder.

Parameters
  • self: the spa json builder object

  • key: the name of the property

void wp_spa_json_builder_add_null(WpSpaJsonBuilder * self)

Adds a null value into the builder.

Parameters
  • self: the spa json builder object

void wp_spa_json_builder_add_boolean(WpSpaJsonBuilder * self, gboolean value)

Adds a boolean value into the builder.

Parameters
  • self: the spa json builder object

  • value: the boolean value

void wp_spa_json_builder_add_int(WpSpaJsonBuilder * self, gint value)

Adds a int value into the builder.

Parameters
  • self: the spa json builder object

  • value: the int value

void wp_spa_json_builder_add_float(WpSpaJsonBuilder * self, float value)

Adds a float value into the builder.

Parameters
  • self: the spa json builder object

  • value: the float value

void wp_spa_json_builder_add_string(WpSpaJsonBuilder * self, const gchar * value)

Adds a string value into the builder.

Parameters
  • self: the spa json builder object

  • value: the string value

void wp_spa_json_builder_add_json(WpSpaJsonBuilder * self, WpSpaJson * json)

Adds a json value into the builder.

Parameters
  • self: the spa json builder object

  • json: (transfer none): the json value

void wp_spa_json_builder_add_from_string(WpSpaJsonBuilder * self, const gchar * json_str)

Adds a json string into the builder.

Parameters
  • self: the spa json builder object

  • json_str: the json string

void wp_spa_json_builder_add_from_stringn(WpSpaJsonBuilder * self, const gchar * json_str, size_t len)

Adds a json string with specific length into the builder.

Parameters
  • self: the spa json builder object

  • json_str: the json string

  • len: the specific length of the json string

void wp_spa_json_builder_add(WpSpaJsonBuilder * self, ...)

Adds values into the builder.

Parameters
  • self: the spa json builder object

  • ...: the json values

void wp_spa_json_builder_add_valist(WpSpaJsonBuilder * self, va_list args)

This is the va_list version of wp_spa_json_builder_add()

Parameters

WpSpaJson* wp_spa_json_builder_end(WpSpaJsonBuilder * self)

Ends the builder process and returns the constructed spa json object.

Return

(transfer full): the constructed spa json object

Parameters
  • self: the spa json builder object

WpSpaJsonParser* wp_spa_json_parser_ref(WpSpaJsonParser * self)

Increases the reference count of a spa json parser.

Return

(transfer full): self with an additional reference count on it

Parameters
  • self: a spa json parser object

void wp_spa_json_parser_unref(WpSpaJsonParser * self)

Decreases the reference count on self and frees it when the ref count reaches zero.

Parameters
  • self: (transfer full): a spa json parser object

WpSpaJsonParser* wp_spa_json_parser_new_array(WpSpaJson * json)

Creates a spa json array parser. The json object must be valid for the entire life-cycle of the returned parser.

Return

(transfer full): The new spa json parser

Parameters
  • json: the spa json array to parse

WpSpaJsonParser* wp_spa_json_parser_new_object(WpSpaJson * json)

Creates a spa json object parser. The json object must be valid for the entire life-cycle of the returned parser.

Return

(transfer full): The new spa json parser

Parameters
  • json: the spa json object to parse

WpSpaJsonParser* wp_spa_json_parser_new_undefined(WpSpaJson * json)

Creates a new spa json parser for undefined type of data. The json object must be valid for the entire life-cycle of the returned parser.

This function allows creating a parser object for any type of spa json and is mostly useful to parse non-standard JSON data that should be treated as if it were an object or array, but does not start with a ‘{‘ or ‘[‘ character. Such data can be for instance a comma-separated list of single values (array) or key-value pairs (object). Such data is also the main configuration file, which is an object but doesn’t start with a ‘{‘ character.

Note

If the data is an array or object, the parser will not enter it and the only token it will be able to parse is the same json object that is passed in as an argument. Use wp_spa_json_parser_new_array() or wp_spa_json_parser_new_object() to parse arrays or objects.

Return

(transfer full): The new spa json parser

Since

0.5.0

Parameters
  • json: the spa json to parse

gboolean wp_spa_json_parser_get_null(WpSpaJsonParser * self)

Gets the null value from a spa json parser.

Return

TRUE if the null value is present, FALSE otherwise

Parameters
  • self: the spa json parser object

gboolean wp_spa_json_parser_get_boolean(WpSpaJsonParser * self, gboolean * value)

Gets the boolean value from a spa json parser.

Return

TRUE if the value was obtained, FALSE otherwise

Parameters
  • self: the spa json parser object

  • value: (out): the boolean value

gboolean wp_spa_json_parser_get_int(WpSpaJsonParser * self, gint * value)

Gets the int value from a spa json parser object.

Return

TRUE if the value was obtained, FALSE otherwise

Parameters
  • self: the spa json parser object

  • value: (out): the int value

gboolean wp_spa_json_parser_get_float(WpSpaJsonParser * self, float * value)

Gets the float value from a spa json parser object.

Return

TRUE if the value was obtained, FALSE otherwise

Parameters
  • self: the spa json parser object

  • value: (out): the float value

gchar* wp_spa_json_parser_get_string(WpSpaJsonParser * self)

Gets the string value from a spa json parser object.

Return

(transfer full): The newly allocated parsed string

Parameters
  • self: the spa json parser object

WpSpaJson* wp_spa_json_parser_get_json(WpSpaJsonParser * self)

Gets the spa json value from a spa json parser object.

Note

the returned spa json object references the original data instead of copying it, therefore the original data must be valid for the entire life-cycle of the returned object

Return

(transfer full): The spa json value or NULL if it could not be obtained

Parameters
  • self: the spa json parser object

gboolean wp_spa_json_parser_get(WpSpaJsonParser * self, ...)

Gets the values from a spa json parser object.

Return

TRUE if the value was obtained, FALSE otherwise

Parameters
  • self: the spa json parser object

  • ...: (out): a list of values to get, followed by NULL

gboolean wp_spa_json_parser_get_valist(WpSpaJsonParser * self, va_list args)

This is the va_list version of wp_spa_json_parser_get()

Return

TRUE if the value was obtained, FALSE otherwise

Parameters

WpIterator* wp_spa_json_new_iterator(WpSpaJson * self)

Creates a new iterator for a spa json object.

Return

(transfer full): the new spa json iterator

Parameters
  • self: the spa json object

WP_TYPE_SPA_JSON (wp_spa_json_get_type ())

The WpSpaJson GType.

WP_TYPE_SPA_JSON_BUILDER (wp_spa_json_builder_get_type ())

The WpSpaJsonBuilder GType.

WP_TYPE_SPA_JSON_PARSER (wp_spa_json_parser_get_type ())

The WpSpaJsonParser GType.