JSON::Native
JSON::Native
A drop-in for JSON::Fast — replace use JSON::Fast with use JSON::Native
and the program keeps working — that takes each engine's fastest exact path.
No dependencies.
use JSON::Native;
my $data = from-json('{"a": [1, 2.5, true, null]}');
say $data<a>[1].WHAT; # (Rat) — Raku numerics, not doubles
say to-json($data, :!pretty);
say json-backend; # which path parses here
say json-backend(:write); # and which one writes
Backends
Raku++ answers with its own codec (
engine). An engine that knows this module answersuse JSON::Nativeitself and never reads this file.Rakudo parses with its own built-in copy of JSON::Fast,
Rakudo::Internals::JSON, and writes withJSON::Native::Rakudo, annqp::writer that only Rakudo ever loads (rakudo).mutsu uses the JSON::Fast it ships with (
json-fast).Everywhere,
JSON::Native::Raku— JSON::Fast's behaviour in plain Raku (raku) — answers what the others decline or refuse, and is the whole of the module on any other engine. It is loaded the first time a call needs it.
JSON_NATIVE_BACKEND names one to use instead. One that is not available is
reported on STDERR, and the usual choice is used.