JSON::Native::Raku
JSON::Native::Raku
The pure-Raku half of JSON::Native: a JSON parser and serialiser with no dependencies, which JSON::Native loads only when its native paths stand aside. It can also be used on its own, by full name — it exports nothing, so that loading it at run time can never put its subs over a program's own:
need JSON::Native::Raku;
my $data = JSON::Native::Raku::from-json('{"a": [1, 2.5, true, null]}');
say JSON::Native::Raku::to-json($data, :!pretty);
Its contract is JSON::Fast's, exactly — not "parses JSON and writes JSON" but
"returns what JSON::Fast returns and writes what JSON::Fast writes", down to
the byte, because programs already depend on that text. The behaviour below is
a port of JSON::Fast 0.21.0, written in plain Raku (no nqp::) so that every
engine runs the same code:
from-json(Str() $text, :$immutable, :$allow-jsonc)— integer token →Int, decimal →Rat, exponent form →Num(each the token's own.Numeric),true/false→Bool,null→Any, objects and arrays →Hash/Array, orMap/Listunder:immutable. Content after the document raisesX::JSON::Native::AdditionalContent.to-json(\obj, :$pretty = True, :$spacing = 2, :$sorted-keys, :$enums-as-value, :$level = 0)— NaN and Inf arenullunless$*JSON_NAN_INF_SUPPORTis true.