NAME

Venus::Json - Json Class

ABSTRACT

Json Class for Perl 5

SYNOPSIS

package main;

use Venus::Json;

my $json = Venus::Json->new(
  value => { name => ['Ready', 'Robot'], version => 0.12, stable => !!1, }
);

# $json->encode;

DESCRIPTION

This package provides methods for reading and writing JSON data. Note: This package requires that a suitable JSON library is installed, currently either JSON::XS 3.0+, JSON::PP 2.27105+, or Cpanel::JSON::XS 4.09+. You can use the VENUS_JSON_PACKAGE environment variable to include or prioritize your preferred JSON library.

ATTRIBUTES

This package has the following attributes:

decoder

decoder(CodeRef)

This attribute is read-write, accepts (CodeRef) values, and is optional.

encoder

encoder(CodeRef)

This attribute is read-write, accepts (CodeRef) values, and is optional.

INHERITS

This package inherits behaviors from:

Venus::Kind::Utility

INTEGRATES

This package integrates behaviors from:

Venus::Role::Accessible

Venus::Role::Buildable

Venus::Role::Explainable

Venus::Role::Valuable

METHODS

This package provides the following methods:

decode

decode(string $json) (any)

The decode method decodes the JSON string, sets the object value, and returns the decoded value.

Since 0.01

decode example 1
# given: synopsis;

my $decode = $json->decode('{"codename":["Ready","Robot"],"stable":true}');

# { codename => ["Ready", "Robot"], stable => 1 }

encode

encode() (string)

The encode method encodes the objects value as a JSON string and returns the encoded string.

Since 0.01

encode example 1
# given: synopsis;

my $encode = $json->encode;

# '{ "name": ["Ready", "Robot"], "stable": true, "version": 0.12 }'

ERRORS

This package may raise the following errors:

error: error_on_config

This package may raise an error_on_config exception.

example 1

# given: synopsis;

my $input = {
  throw => 'error_on_config',
};

my $error = $json->catch('error', $input);

# my $name = $error->name;

# "on_config"

# my $message = $error->message;

# "No suitable JSON package"

AUTHORS

Awncorp, awncorp@cpan.org

LICENSE

Copyright (C) 2022, Awncorp, awncorp@cpan.org.

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.