### Function

# GLib Variant parse

#### Declaration [src]

    GVariant*
    g_variant_parse (
      const GVariantType* type,
      const gchar* text,
      const gchar* limit,
      const gchar** endptr,
      GError** error
    )

#### Description [src]

Parses a `GVariant` from a text representation.

A single `GVariant` is parsed from the content of `text`.

The format is described here.

The memory at `limit` will never be accessed and the parser behaves as if the character at `limit` is the nul terminator. This has the effect of bounding `text`.

If `endptr` is non-`NULL` then `text` is permitted to contain data following the value that this function parses and `endptr` will be updated to point to the first character past the end of the text parsed by this function. If `endptr` is `NULL` and there is extra data then an error is returned.

If `type` is non-`NULL` then the value will be parsed to have that type. This may result in additional parse errors (in the case that the parsed value doesn’t fit the type) but may also result in fewer errors (in the case that the type would have been ambiguous, such as with empty arrays).

In the event that the parsing is successful, the resulting `GVariant` is returned. It is never floating, and must be freed with `g_variant_unref()`.

In case of any error, `NULL` will be returned. If `error` is non-`NULL` then it will be set to reflect the error that occurred.

Officially, the language understood by the parser is “any string produced by `g_variant_print()`”. This explicitly includes `g_variant_print()`’s annotated types like `int64 -1000`.

There may be implementation specific restrictions on deeply nested values, which would result in a `G_VARIANT_PARSE_ERROR_RECURSION` error. `GVariant` is guaranteed to handle nesting up to at least 64 levels.

#### Parameters

`type`

  Type: `GVariantType`

  A `GVariantType`, or `NULL`.

  The argument can be `NULL`.
  The data is owned by the caller of the function.

`text`

  Type: `const gchar*`

  A string containing a GVariant in text form.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`limit`

  Type: `const gchar*`

  A pointer to the end of `text`, or `NULL`.

  The argument can be `NULL`.
  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`endptr`

  Type: `const gchar**`

  A location to store the end pointer, or `NULL`.

  The argument can be `NULL`.
  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`error`

  Type: `GError **`

  The return location for a recoverable error.

  The argument can be `NULL`.
  If the return location is not `NULL`, then you must initialize it to a `NULL` `GError*`.
  The argument will be left initialized to `NULL` by the function if there are no errors.
  In case of error, the argument will be set to a newly allocated `GError`; the caller will take ownership of the data, and be responsible for freeing it.

#### Return value

Type: `GVariant`

A non-floating reference to a `GVariant`, or `NULL`.

The caller of the function takes ownership of the data, and is responsible for freeing it.