From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

NAME

FP::JSON

SYNOPSIS

use FP::JSON qw(to_json);
my $settings = {
output_format => "JSON", # or "Mint"
auto_numbers => 1,
auto_integers => 0,
# converter => sub ($obj) { ... convert to accepted data .. },
# pretty => 1, # extra re-parsing step at the end
};
is to_json([10, list(20,30), {40=> "foo", bar=> 50}], $settings),
'[
10,
[
20,
30
],
{
"40": "foo",
"bar": 50
}
]';
$settings->{pretty} = 1;
is to_json([10, list(20,30), {40=> "foo", bar=> 50}], $settings),
'[
10,
[
20,
30
],
{
"40" : "foo",
"bar" : 50
}
]
';

DESCRIPTION

Currently just provides `to_json` to turn some kinds of data into a JSON or Mint language string. This module will need some work for more serious use.

This somewhat consciously is not implemented as a class--nonetheless, the $settings argument to `to_json` is basically $self. Still, isn't it neat how few changes one needs to do from procedural code this way (Ok, all 3 functions now take the settings, though), and there's no need to use a constructor, just bare "data", which is quite en vogue (again) today (e.g. in Clojure, Elixir).

NOTE

This is alpha software! Read the status section in the package README or on the website.