The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Glib::JSON - Perl interface to the JSON-GLib library

SYNOPSIS

use Glib::JSON;

# build a JSON structure
my $builder = Glib::JSON::Builder->new();

# {
#   "url" : "http://www.gnome.org/img/flash/two-thirty.png"
#   "size" : [ 652, 242 ]
# }
$builder->begin_object();

$builder->set_member_name("url");
$builder->add_string_value("http://www.gnome.org/img/flash/two-thirty.png");

$builder->set_member_name("size");
$builder->begin_array();
$builder->add_int_value(652);
$builder->add_int_value(242);
$builder->end_array();

$builder->end_object();

# generate the JSON string
my $generator = Glib::JSON::Generator->new();
$generator->set_root($builder->get_root());
my $data = $generator->to_data();

# load the string into a JSON document
my $parser = Glib::JSON::Parser->new();
$parser->load_from_data($data);

# parse the document
my $reader = Glib::JSON::Reader->new();
$reader->set_root($parser->get_root());

$reader->read_member("url");
my $url = $reader->get_string_value();
$render->end_member();

$render->read_member("size");
$reader->read_element(0);
my $width = $reader->get_int_value();
$reader->end_element();
$reader->read_element(1);
my $height = $reader->get_int_value();
$reader->end_element();
$reader->end_member();

DESCRIPTION

Glib::JSON is a Perl module that provides access to the JSON-GLib library through introspection.

Glib::JSON allows parsing and generating JSON documents through a simple, DOM-like API; it also provides cursor-based API to parse and generate JSON documents.

Glib::JSON is integrated with the GLib and GObject data types, and can easily serialize and deserialize JSON data from and to GObject instances.

SEE ALSO

Glib
Glib::Object::Introspection

AUTHORS

Emmanuele Bassi <ebassi@gnome.org>

COPYRIGHT AND LICENSE

Copyright (C) 2014 Emmanuele Bassi

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.