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, or Map/List under :immutable. Content after the document raises X::JSON::Native::AdditionalContent.

  • to-json(\obj, :$pretty = True, :$spacing = 2, :$sorted-keys, :$enums-as-value, :$level = 0) — NaN and Inf are null unless $*JSON_NAN_INF_SUPPORT is true.

JSON::Native v0.1.0

JSON parsing and writing, a drop-in for JSON::Fast that takes each engine's fastest path — Raku++'s built-in codec, Rakudo's own — with pure Raku everywhere else

Authors

  • Andrew Shitov

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • JSON::Native
  • JSON::Native::Raku
  • JSON::Native::Rakudo

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.