Write JSON with simplicities
$ cpan App::cpanminus
$ cpanm git://github.com/lucas1/WJSON.git
use WJSON;
my $json = new WJSON;
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
print $json->Print;
set encoding, default utf-8
set variable and return: var get_variable = {}
set ordering with 1 or true and return json order by position
Open object or array
Close object or array
Create object with prototyped set of key/value (properties)
Create hash object with prototyped set of {key/value} (properties)
Create array, set of value
Return "application/json"
Return "application/javascript"
Return "Content-type: application/json\n\n"
Return "Content-type: application/javascript\n\n"
Print JSON
my $json = new WJSON(encoding => 'iso-8859-1');
$json->Array('value_1', 'value_2', 'value_3');
print $json->Print;
["value_1", "value_2", "value_3"]
my $json = new WJSON;
$json->encoding('iso-8859-1');
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
print $json->Print;
{
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2"
}
my $json = new WJSON;
$json->HashObject(
{
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
}
);
print $json->Print;
[{
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2"
}]
my $json = new WJSON;
$json->Open('Data');
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
$json->Close;
print $json->Print;
{
"Data": {
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2"
}
}
my $json = new WJSON;
$json->Open('Data');
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
$json->Close;
print $json->Print;
{
"Data": [{
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2"
}, {
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2"
}]
}
my $json = new WJSON;
$json->Open('Data');
$json->Array('value_1', 'value_2', 'value_3');
$json->Close;
print $json->Print;
{
"Data": ["value_1", "value_2", "value_3"]
}
my $json = new WJSON;
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
$json->Open('Data');
$json->Open('SubData');
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
$json->Object(
key_1 => 'value_1',
key_2 => 'value_2',
key_3 => 'value_3',
);
$json->Close;
$json->Array(['value_1', 'value_2', 'value_3'], ['value_4', 'value_5']);
$json->Array(['value_6', 'value_7']);
$json->Close;
$json->Array(['value_1', 'value_2', 'value_3'], ['value_4', 'value_5']);
print $json->Print;
[{
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2"
}, {
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2",
"Data": [{
"SubData": [{
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2"
}, {
"key_3": "value_3",
"key_1": "value_1",
"key_2": "value_2"
}]
},
["value_1", "value_2", "value_3"],
["value_4", "value_5"], "value_6", "value_7"
]
},
["value_1", "value_2", "value_3"],
["value_4", "value_5"]
]
my $json = new WJSON;
$json->variable('json');
$json->Object(
key_1 => 'Formulário',
key_2 => 'value_2',
key_3 => 'value_3',
);
print $json->Print;
var json = {
"key_3": "value_3",
"key_1": "Formulário",
"key_2": "value_2"
};
Lucas Tiago de Moraes, lucastiagodemoraes@gmail.com