Class

JsonParser

since: 1.0

Description [src]

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

JsonParser provides an object for parsing a JSON data stream, either inside a file or inside a static buffer.

Using JsonParser

The JsonParser API is fairly simple:

gboolean
parse_json (const char *filename)
{
  g_autoptr(JsonParser) parser = json_parser_new ();
  g_autoptr(GError) error = NULL

  json_parser_load_from_file (parser, filename, &error);
  if (error != NULL)
    {
      g_critical ("Unable to parse '%s': %s", filename, error->message);
      return FALSE;
    }

  g_autoptr(JsonNode) root = json_parser_get_root (parser);

  // manipulate the object tree from the root node

  return TRUE
}

By default, the entire process of loading the data and parsing it is synchronous; the [method@Json.Parser.load_from_stream_async()] API will load the data asynchronously, but parse it in the main context as the signals of the parser must be emitted in the same thread. If you do not use signals, and you wish to also parse the JSON data without blocking, you should use a GTask and the synchronous JsonParser API inside the task itself.

Available since: 1.0

Hierarchy

hierarchy this JsonParser ancestor_0 GObject ancestor_0--this

Ancestors

Constructors

json_parser_new

Creates a new JSON parser.

since: 1.0

json_parser_new_immutable

Creates a new parser instance with its JsonParser:immutable property set to TRUE to create immutable output trees.

since: 1.2

Instance methods

json_parser_get_current_line

Retrieves the line currently parsed, starting from 1.

since: 1.0

json_parser_get_current_pos

Retrieves the current position inside the current line, starting from 0.

since: 1.0

json_parser_get_root

Retrieves the top level node from the parsed JSON stream.

since: 1.0

json_parser_has_assignment

A JSON data stream might sometimes contain an assignment, like:

since: 0.4

json_parser_load_from_data

Loads a JSON stream from a buffer and parses it.

since: 1.0

json_parser_load_from_file

Loads a JSON stream from the content of filename and parses it.

since: 1.0

json_parser_load_from_mapped_file

Loads a JSON stream from the content of filename and parses it.

since: 1.6

json_parser_load_from_stream

Loads the contents of an input stream and parses them.

since: 0.12

json_parser_load_from_stream_async

Asynchronously reads the contents of a stream.

since: 0.12

json_parser_load_from_stream_finish

Finishes an asynchronous stream loading started with json_parser_load_from_stream_async().

since: 0.12

json_parser_steal_root

Steals the top level node from the parsed JSON stream.

since: 1.4

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Properties

Json.Parser:immutable

Whether the tree built by the parser should be immutable when created.

since: 1.2

Signals

Json.Parser::array-element

The ::array-element signal is emitted each time a parser has successfully parsed a single element of a JSON array.

since: 1.0

Json.Parser::array-end

The ::array-end signal is emitted each time a parser has successfully parsed an entire JSON array.

since: 1.0

Json.Parser::array-start

The ::array-start signal is emitted each time a parser starts parsing a JSON array.

since: 1.0

Json.Parser::error

The ::error signal is emitted each time a parser encounters an error in a JSON stream.

since: 1.0

Json.Parser::object-end

The ::object-end signal is emitted each time a parser has successfully parsed an entire JSON object.

since: 1.0

Json.Parser::object-member

The ::object-member signal is emitted each time a parser has successfully parsed a single member of a JSON object.

since: 1.0

Json.Parser::object-start

This signal is emitted each time a parser starts parsing a JSON object.

since: 1.0

Json.Parser::parse-end

This signal is emitted when a parser successfully finished parsing a JSON data stream.

since: 1.0

Json.Parser::parse-start

This signal is emitted when a parser starts parsing a JSON data stream.

since: 1.0

Signals inherited from GObject (1)
GObject::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

unstable since: 2.0

Class structure

struct JsonParserClass {
  void (* parse_start) (
    JsonParser* parser
  );
  void (* object_start) (
    JsonParser* parser
  );
  void (* object_member) (
    JsonParser* parser,
    JsonObject* object,
    const gchar* member_name
  );
  void (* object_end) (
    JsonParser* parser,
    JsonObject* object
  );
  void (* array_start) (
    JsonParser* parser
  );
  void (* array_element) (
    JsonParser* parser,
    JsonArray* array,
    gint index_
  );
  void (* array_end) (
    JsonParser* parser,
    JsonArray* array
  );
  void (* parse_end) (
    JsonParser* parser
  );
  void (* error) (
    JsonParser* parser,
    const GError* error
  );
  void (* _json_reserved1) (
void
  );
  void (* _json_reserved2) (
void
  );
  void (* _json_reserved3) (
void
  );
  void (* _json_reserved4) (
void
  );
  void (* _json_reserved5) (
void
  );
  void (* _json_reserved6) (
void
  );
  void (* _json_reserved7) (
void
  );
  void (* _json_reserved8) (
void
  );
  
}

The class structure for the JsonParser type.

Class members
parse_start: void (* parse_start) ( JsonParser* parser )
No description available.
object_start: void (* object_start) ( JsonParser* parser )
No description available.
object_member: void (* object_member) ( JsonParser* parser, JsonObject* object, const gchar* member_name )
No description available.
object_end: void (* object_end) ( JsonParser* parser, JsonObject* object )
No description available.
array_start: void (* array_start) ( JsonParser* parser )
No description available.
array_element: void (* array_element) ( JsonParser* parser, JsonArray* array, gint index_ )
No description available.
array_end: void (* array_end) ( JsonParser* parser, JsonArray* array )
No description available.
parse_end: void (* parse_end) ( JsonParser* parser )
No description available.
error: void (* error) ( JsonParser* parser, const GError* error )
No description available.
_json_reserved1: void (* _json_reserved1) ( void )
No description available.
_json_reserved2: void (* _json_reserved2) ( void )
No description available.
_json_reserved3: void (* _json_reserved3) ( void )
No description available.
_json_reserved4: void (* _json_reserved4) ( void )
No description available.
_json_reserved5: void (* _json_reserved5) ( void )
No description available.
_json_reserved6: void (* _json_reserved6) ( void )
No description available.
_json_reserved7: void (* _json_reserved7) ( void )
No description available.
_json_reserved8: void (* _json_reserved8) ( void )
No description available.

Virtual methods

Json.ParserClass.array_element
No description available.

since: 1.0

Json.ParserClass.array_end
No description available.

since: 1.0

Json.ParserClass.array_start
No description available.

since: 1.0

Json.ParserClass.error
No description available.

since: 1.0

Json.ParserClass.object_end
No description available.

since: 1.0

Json.ParserClass.object_member
No description available.

since: 1.0

Json.ParserClass.object_start
No description available.

since: 1.0

Json.ParserClass.parse_end
No description available.

since: 1.0

Json.ParserClass.parse_start
No description available.

since: 1.0