Skip to content

Commit

Permalink
Squashed 'ext/JSON__Fast/' changes from 8ad8c77..6d96209
Browse files Browse the repository at this point in the history
6d96209 Merge pull request #11 from moritz/meta
acb56ba Remove the leading "v" in the version
c76eb61 remove leading v in perl version definition in meta info
b177612 Merge pull request #10 from zoffixznet/docs
fb90aaf Document exported subs

git-subtree-dir: ext/JSON__Fast
git-subtree-split: 6d9620956d1606441ad32bb23193d997772c615a
  • Loading branch information
niner committed Feb 22, 2016
1 parent 1fb6f9f commit 899dbdf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions META6.json
@@ -1,8 +1,8 @@
{
"perl" : "v6",
"perl" : "6",
"name" : "JSON::Fast",
"description" : "A naive, fast json parser and serializer; drop-in replacement for JSON::Tiny",
"version" : "v0.3",
"version" : "0.3",
"test-depends" : [
"Test"
],
Expand Down
35 changes: 34 additions & 1 deletion README.md
@@ -1,4 +1,4 @@
# json_fast
# JSON::Fast

a naive imperative json parser in pure perl6 (but with direct access to nqp:: ops), to evaluate performance against JSON::Tiny. It is a drop-in replacement for JSON::Tiny's from-json sub.

Expand All @@ -7,3 +7,36 @@ Currently it seems to be about 5x faster and uses up about a fourth of the RAM.
There should be some more speed attainable through tuning, micro-optimizations, re-introducing the block flattening optimization in rakudo and other stuff.

This module also includes a very fast to-json function that tony-o created in tony-o/perl6-json-faster.

# Exported subroutines

## `to-json`

```perl6
say to-json [<my Perl data structure>];
say to-json [<my Perl data structure>], :!pretty;
say to-json [<my Perl data structure>], :spacing(4);
```

Encode a Perl data structure into JSON. Takes one positional argument, which
is a thing you want to encode into JSON. Takes these optional named arguments:

### `pretty`

`Bool`. Defaults to `True`. Specifies whether the output should be "pretty",
human-readable JSON.

### `spacing`

`Int`. Defaults to `2`. Applies only when [`pretty`](#pretty) is `True`.
Controls how much spacing there is between each nested level of the output.

## `from-json`

```perl6
my $x = from-json '["foo", "bar", {"ber": "bor"}]';
say $x.perl;
# outputs: $["foo", "bar", {:ber("bor")}]
```
Takes one positional argument that is coerced into a `Str` type and represents
a JSON text to decode. Returns a Perl datastructure representing that JSON.

0 comments on commit 899dbdf

Please sign in to comment.