JsonParser

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

Using json.parser.Parser

The json.parser.Parser 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 json.parser.Parser.loadFromStreamAsync 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 gio.task.Task and the synchronous json.parser.Parser API inside the task itself.

Members

Variables

parentInstance
ObjectC parentInstance;
priv
JsonParserPrivate* priv;