Json.Reader
Description: Reference for Json.Reader

### Class

# JsonReader

#### Description [src]

    class Json.Reader : GObject.Object {
      /* No available fields */
    }

`JsonReader` provides a simple, cursor-based API for parsing a JSON DOM.

It is similar, in spirit, to the XML Reader API.

## Using `JsonReader`

    g_autoptr(JsonParser) parser = json_parser_new ();

    // str is defined elsewhere
    json_parser_load_from_data (parser, str, -1, NULL);

    g_autoptr(JsonReader) reader = json_reader_new (json_parser_get_root (parser));

    json_reader_read_member (reader, "url");
      const char *url = json_reader_get_string_value (reader);
      json_reader_end_member (reader);

    json_reader_read_member (reader, "size");
      json_reader_read_element (reader, 0);
        int width = json_reader_get_int_value (reader);
        json_reader_end_element (reader);
      json_reader_read_element (reader, 1);
        int height = json_reader_get_int_value (reader);
        json_reader_end_element (reader);
      json_reader_end_member (reader);

## Error handling

In case of error, `JsonReader` will be set in an error state; all subsequent calls will simply be ignored until a function that resets the error state is called, e.g.:

    // ask for the 7th element; if the element does not exist, the
    // reader will be put in an error state
    json_reader_read_element (reader, 6);

    // in case of error, this will return NULL, otherwise it will
    // return the value of the element
    str = json_reader_get_string_value (value);

    // this function resets the error state if any was set
    json_reader_end_element (reader);

If you want to detect the error state as soon as possible, you can use `json_reader_get_error()`:

    // like the example above, but in this case we print out the
    // error immediately
    if (!json_reader_read_element (reader, 6))
      {
        const GError *error = json_reader_get_error (reader);
        g_print ("Unable to read the element: %s", error->message);
      }

Available since: | 0.12

#### Ancestors

- GObject

#### Constructors

###### json_reader_new

Creates a new reader.

Available since: 0.12

#### Instance methods

###### json_reader_count_elements

Counts the elements of the current position, if the reader is positioned on an array.

Available since: 0.12

###### json_reader_count_members

Counts the members of the current position, if the reader is positioned on an object.

Available since: 0.12

###### json_reader_end_element

Moves the cursor back to the previous node after being positioned inside an array.

Available since: 0.12

###### json_reader_end_member

Moves the cursor back to the previous node after being positioned inside an object.

Available since: 0.12

###### json_reader_get_boolean_value

Retrieves the boolean value of the current position of the reader.

Available since: 0.12

###### json_reader_get_double_value

Retrieves the floating point value of the current position of the reader.

Available since: 0.12

###### json_reader_get_error

Retrieves the error currently set on the reader.

Available since: 0.12

###### json_reader_get_int_value

Retrieves the integer value of the current position of the reader.

Available since: 0.12

###### json_reader_get_member_name

Retrieves the name of the current member.

Available since: 0.14

###### json_reader_get_null_value

Checks whether the value of the current position of the reader is `null`.

Available since: 0.12

###### json_reader_get_string_value

Retrieves the string value of the current position of the reader.

Available since: 0.12

###### json_reader_get_value

Retrieves the value node at the current position of the reader.

Available since: 0.12

###### json_reader_is_array

Checks whether the reader is currently on an array.

Available since: 0.12

###### json_reader_is_object

Checks whether the reader is currently on an object.

Available since: 0.12

###### json_reader_is_value

Checks whether the reader is currently on a value.

Available since: 0.12

###### json_reader_list_members

Retrieves a list of member names from the current position, if the reader is positioned on an object.

Available since: 0.14

###### json_reader_read_element

Advances the cursor of the reader to the element of the array or the member of the object at the given position.

Available since: 0.12

###### json_reader_read_member

Advances the cursor of the reader to the `member_name` of the object at the current position.

Available since: 0.12

###### json_reader_set_root

Sets the root node of the JSON tree to be read by `reader`.

Available since: 0.12

#### Properties

###### Json.Reader:root

The root of the JSON tree that the reader should read.

Available since: 0.12

#### Class structure

    struct JsonReaderClass {
      void (* _json_padding0) (
    void
      );
      void (* _json_padding1) (
    void
      );
      void (* _json_padding2) (
    void
      );
      void (* _json_padding3) (
    void
      );
      void (* _json_padding4) (
    void
      );

    }

###### Class members

`_json_padding0` |
    void (* _json_padding0) (
    void
      )
| No description available.
`_json_padding1` |
    void (* _json_padding1) (
    void
      )
| No description available.
`_json_padding2` |
    void (* _json_padding2) (
    void
      )
| No description available.
`_json_padding3` |
    void (* _json_padding3) (
    void
      )
| No description available.
`_json_padding4` |
    void (* _json_padding4) (
    void
      )
| No description available.