JSON::Decode::Marpa - JSON parser using Marpa
This document describes version 0.02 of JSON::Decode::Marpa (from Perl distribution JSON-Decode-Marpa), released on 2014-08-27.
use JSON::Decode::Marpa qw(from_json); my $data = from_json(q([1, true, "a", {"b":null}]));
This module is based on MarpaX::Demo::JSONParser (using json.2.bnf), but offers a more convenient interface for JSON decoding. I packaged this for casual benchmarking against Pegex::JSON and JSON::Decode::Regexp.
json.2.bnf
The result on my computer: Pegex::JSON and JSON::Decode::Marpa are roughly the same speed (but Pegex has a much smaller startup overhead than Marpa). JSON::Decode::Regexp is about an order of magnitude faster than this module, and JSON::XS is about three orders of magnitude faster. So that's that.
This is the benchmark code used:
use 5.010; use strict; use warnings; use Benchmark qw(timethese); use JSON::Decode::Marpa (); use JSON::Decode::Regexp (); use JSON::XS (); use Pegex::JSON; my $json = q([1,"abc\ndef",-2.3,null,[],[1,2,3],{},{"a":1,"b":2}]); my $pgx = Pegex::JSON->new; timethese -0.5, { pegex => sub { $pgx->load($json) }, regexp => sub { JSON::Decode::Regexp::from_json($json) }, marpa => sub { JSON::Decode::Marpa::from_json($json) }, xs => sub { JSON::XS::decode_json($json) }, };
Decode JSON in $str. Dies on error.
$str
JSON, JSON::PP, JSON::XS, JSON::Tiny, JSON::Decode::Regexp, Pegex::JSON.
Please visit the project's homepage at https://metacpan.org/release/JSON-Decode-Marpa.
Source repository is at https://github.com/perlancar/perl-JSON-Decode-Marpa.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-Decode-Marpa
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2014 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install JSON::Decode::Marpa, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON::Decode::Marpa
CPAN shell
perl -MCPAN -e shell install JSON::Decode::Marpa
For more information on module installation, please visit the detailed CPAN module installation guide.