NAME

SPVM::JSON - JSON serializing/deserializing

SYNOPSYS

use SPVM::JSON;

# new
my $json = SPVM::JSON->new;

# decode
$json->decode($json_text);

# set the canonical flag on
$json->set_canonical(1);

# encode
my $encoded_json = $json->encode($spvm_data);

DESCRIPTION

SPVM::JSON converts SPVM data structures to JSON and vice versa.

CLASS METHODS

new

sub new : SPVM::JSON ()

Create new SPVM::JSON object that can be used to de/encode JSON strings.

INSTANCE METHODS

encode

sub encode : string ($self : self, $object : object)

Converts the given SPVM data structure (undef or a object of numeric, string, SPVM::JSON::Bool, SPVM::Hash or SPVM::ObjectList) to its JSON representation.

decode

sub decode : object ($self : self, $json : string)

The opposite of encode: expects a JSON text and tries to parse it, returning the resulting object. Dies on error. Numbers in a JSON text are converted to SPVM::Double.

set_canonical

sub set_canonical : void ($self : self, $enable : byte)

If $enable is true, then the encode method will output JSON objects by sorting their keys. This is adding a comparatively high overhead.

canonical

sub canonical : byte ($self : self)

Get the canonical flag.