Giter Site home page Giter Site logo

json_fast's Introduction

Build Status

JSON::Fast

A naive imperative JSON parser in pure Raku (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 and to-json subs, but it offers a few extra features.

Currently it seems to be about 4x faster and uses up about a quarter of the RAM JSON::Tiny would use.

This module also includes a very fast to-json function that tony-o created and lizmat later completely refactored.

SYNOPSIS

    use JSON::Fast;
    my $storage-path = $*SPEC.tmpdir.child("json-fast-example-$*PID.json");
    say "using path $storage-path for example";
    for <recreatable monascidian spectrograph bardiest ayins sufi lavanga Dachia> -> $word {
        say "- loading json file";
        my $current-data = from-json ($storage-path.IO.slurp // "\{}");
        # $current-data now contains a Hash object populated with what was in the file
        # (or an empty hash in the very first step when the file didn't exsit yet)

        say "- adding entry for $word";
        $current-data{$word}{"length"} = $word.chars;
        $current-data{$word}{"first letter"} = $word.substr(0,1);

        say "- saving json file";
        $storage-path.IO.spurt(to-json $current-data);
        # to-json gives us a regular string, so we can plop that
        # into the file with the spurt method

        say "json file is now $storage-path.IO.s() bytes big";
        say "===";
    }
    say "here is the entire contents of the json file:";
    say "====";
    say $storage-path.IO.slurp();
    say "====";
    say "deleting storage file ...";
    $storage-path.IO.unlink;

Exported subroutines

to-json

    my $*JSON_NAN_INF_SUPPORT = 1; # allow NaN, Inf, and -Inf to be serialized.
    say to-json [<my Raku data structure>];
    say to-json [<my Raku data structure>], :!pretty;
    say to-json [<my Raku data structure>], :spacing(4);

    enum Blerp <Hello Goodbye>;
    say to-json [Hello, Goodbye]; # ["Hello", "Goodbye"]
    say to-json [Hello, Goodbye], :enums-as-value; # [0, 1]

Encode a Raku 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. When set to False, will output json in a single line.

spacing

Int. Defaults to 2. Applies only when pretty is True. Controls how much spacing there is between each nested level of the output.

sorted-keys

Specifies whether keys from objects should be sorted before serializing them to a string or if $obj.keys is good enough. Defaults to False. Can also be specified as a Callable with the same type of argument that the .sort method accepts to provide alternate sorting methods.

enum-as-value

Bool, defaults to False. Specifies whether enums should be json-ified as their underlying values, instead of as the name of the enum.

from-json

    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 Raku datastructure representing that JSON.

immutable

Bool. Defaults to False. Specifies whether Hashes and Arrays should be rendered as immutable datastructures instead (as Map / List. Creating an immutable data structures is mostly saving on memory usage, and a little bit on CPU (typically around 5%).

This also has the side effect that elements from the returned structure can now be iterated over directly because they are not containerized.

    my %hash := from-json "META6.json".IO.slurp, :immutable;
    say "Provides:";
    .say for %hash<provides>;

allow-jsonc

Bool. Defaults to False. Specifies whether commmands adhering to the JSONC standard are allowed.

Additional features

Adapting defaults of "from-json"

In the use statement, you can add the string "immutable" to make the default of the immutable parameter to the from-json subroutine True, rather than False.

    use JSON::Fast <immutable>;  # create immutable data structures by default

Adapting defaults of "to-json"

In the use statement, you can add the strings "!pretty", "sorted-keys" and/or "enums-as-value" to change the associated defaults of the to-json subroutine.

    use JSON::FAST <!pretty sorted-keys enums-as-value>;

Strings containing multiple json pieces

When the document contains additional non-whitespace after the first successfully parsed JSON object, JSON::Fast will throw the exception X::JSON::AdditionalContent. If you expect multiple objects, you can catch that exception, retrieve the parse result from its parsed attribute, and remove the first rest-position characters off of the string and restart parsing from there.

json_fast's People

Contributors

akiym avatar alexdaniel avatar altai-man avatar coke avatar curttilmes avatar gfldex avatar japhb avatar jonathanstowe avatar kaiepi avatar lizmat avatar moritz avatar samcv avatar timo avatar tony-o avatar tyil avatar wukgdu avatar zoffixznet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

json_fast's Issues

Cannot to-json(Seq) etc

In #2, to-json function changed drastically.

In https://github.com/timo/json_fast/blob/master/lib/JSON/Fast.pm#L19,
to-json checks whether $obj is array-like or not by ~~ Array.
Then Seq, List, ... is not array-like and to-json(Seq) does not work.

> perl6 -MJSON::Fast -e 'my $a = gather for 1..5 { take $_ }; $a.WHAT.say; to-json $a'
(Seq)
# HANG UP!
# actually throws exception many times: Type Seq does not support associative indexing.

I think we should check whether $obj is array-like or not by multi to-json(Positional:D $obj) as before.

IntStr.new(0, '') creates a broken json that can not be parsed anymore

This code:

        dd %.data;
        say to-json( %.data ); 

produces this output:

Hash %!data = {:host("xxxx.loc"), :password("xxxx"), :port(8443), :prefix(IntStr.new(0, "")), :protocol("http"), :user("xxx")}
{
  "port": 8443,
  "prefix": ,
  "protocol": "http",
  "host": "xxxx.loc",
  "password": "xxx",
  "user": "xxx"
}

The problem is the "prefix": ,

Don't know how to jsonify Complex

So it seems like Complex should be in the list, but is there any way around this without modifying the code to JSON::Fast itself? The type handling appears to be all hard-coded. Seems like falling back to whatever the stringification is would make sense.

Tests fail while bootstraping panda

 ==> Fetching JSON::Fast
 ==> Building JSON::Fast
 ==> Testing JSON::Fast
 t/01-parse.t ...... ok
 t/02-structure.t .. ok
 t/03-unicode.t .... ok
 at 67: can't parse objects starting in F yet
   in sub parse-thing at /home/travis/.rakudobrew/moar-nom/panda/.panda-work/1448285181_3/lib/JSON/Fast.pm:272
   in sub parse-obj at /home/travis/.rakudobrew/moar-nom/panda/.panda-work/1448285181_3/lib/JSON/Fast.pm:167
   in sub from-json at /home/travis/.rakudobrew/moar-nom/panda/.panda-work/1448285181_3/lib/JSON/Fast.pm:291
   in block <unit> at t/04-roundtrip.t:36
 # Looks like you planned 17 tests, but ran 16
 t/04-roundtrip.t .. 
 Dubious, test returned 255 (wstat 65280, 0xff00)
 Failed 1/17 subtests 

Could JSON::Fast support multiple JSON objects?

I realize this is my problem, not yours, but an external provider who is supposed to send JSON is actually sending me multiple JSON objects, Think something like this:

{ "a": 1 }{ "b": 2 }{ "c": 3 }

JSON::Fast correctly throws an Exception because of the extra garbage after a successful parse.

I am trying to figure out the right approach to solve my problem. Though I could fork JSON::Fast and make a JSON::Fast::Multi or some such, that would give me all sorts of other problems, keeping things in sync, etc.

I am wondering if you would be open to one of two approaches:

  1. Add a :multi option to from-json() that instead of dying would just keep parsing and return all the objects in an array, something like this:
our sub from-json(Str() $text, Bool :$multi) is export {
    my str $ntext = $text;
    my int $length = $text.chars;
    my int $pos = 0;
    my @results;
    loop {
        my $result = parse-thing($text, $pos);
        try nom-ws($text, $pos);
        if $multi {
            @results.push($result);
            if $pos == nqp::chars($text) {
                return @results.elems == 1 ?? @results[0] !! @results;
            }
        }
        else {
            return $result if $pos == nqp::chars($text);
            die "additional text after the end of the document: { substr($text, $pos).perl }";
        }
    }
}
  1. Leave everything exactly as it is, but add an extra from-json-multi() function something like this:
our sub from-json-multi(Str() $text) is export {
    my str $ntext = $text;
    my int $length = $text.chars;
    my int $pos = 0;
    my @results;
    repeat {
        @results.push: parse-thing($text, $pos);
        try nom-ws($text, $pos);
    } until $pos == nqp::chars($text);
    return @results.elems == 1 ?? @results[0] !! @results;
}

:!pretty now inserts newlines

Previously, using :!pretty would promise a single line of output. This meant it could be used to produce JSONLines. A recent change has made it insert newlines with :!pretty, which breaks modules that (like Log::Timeline) that relied on the previous behavior.

does not escape null bytes or control characters

As per JSON RFC:
All Unicode characters may be placed within the
quotation marks, except for the characters that must be escaped:
quotation mark, reverse solidus, and the control characters (U+0000
through U+001F).

Need a good, practical user example in the README or in examples

I appreciate and use JSON::Fast when I need easy data storage and retrieval, but I usually have to fiddle with how to incorporate it because I've forgotten how I did it the last time.

For someone who only wants to use JSON for data storage and retrieval, a simple example would be useful. Said example would look something like this:

use JSON::Fast;
my %h;
# add some data to the hash...
# name a file for storage
my $jfil = "/path/to/some-data.json";
# convert the hash to JSON
my $jstr = to-json %h;
# save the JSON string to disk
spurt $jfil, $jstr;

Then, another prog uses that data store:

use JSON::Fast;
my $jfil = "/path/to/some-data.json";
my $jstr = slurp $jfil;
my %h = from-json $jstr;
# use the hash...

Of cousrse having methods to allow those steps to be done at one call would be even more useful.

Memory leak

Compared to JSON::Tiny it is leaking like hell. I noticed it after Pastebin::Gist switched back to JSON::Fast in raku-community-modules/Pastebin-Gist@45c2512.

I'm observing the issue through unicodable, but I guess you can also reproduce it separately.

unicodable6test: { 0 < $_ < 8000 }
<unicodable6test> naxieAlDle, U+0001 <control-0001> [Cc] (control character)
<unicodable6test> naxieAlDle, U+0002 <control-0002> [Cc] (control character)
<unicodable6test> naxieAlDle, 7999 characters in total: https://gist.github.com/a14b9d38cbdc7500c80cf32752efe0c9

… Meanwhile it is using several gigs of memory just because of this gist alone!

to-json routine is no longer escaping double quotes in hash keys

A very annoying bug popped up in the latest version. The to-json routine in no longer properly escaping double quote in hash key strings. It's probably not a common thing, but it happens. I have moderately large JSON files files I process every sunday and they failed hard after I had upgraded to 2020.07 and updated all my installed modules.

use JSON::Fast;
my %data = 'It\'s the "REAL" deal!' => 'BORKEN!!';
say my $json = %data.&to-json;
say "WAT!? The double quotes aren't escaped... that isn't valid JSON";
say $json.&from-json

Output

{
  "It's the "REAL" deal!": "BORKEN!!"
}
WAT!? The double quotes aren't escaped... that isn't valid JSON
unexpected R in an object at 15
  in block  at /home/steve/.perl6/share/perl6/site/sources/0FE3EE5CA05AEDC84BC326E7EBBACCB6647BD427 (JSON::Fast) line 594
  in sub parse-obj at /home/steve/.perl6/share/perl6/site/sources/0FE3EE5CA05AEDC84BC326E7EBBACCB6647BD427 (JSON::Fast) line 556
  in sub parse-thing at /home/steve/.perl6/share/perl6/site/sources/0FE3EE5CA05AEDC84BC326E7EBBACCB6647BD427 (JSON::Fast) line 647
  in sub from-json at /home/steve/.perl6/share/perl6/site/sources/0FE3EE5CA05AEDC84BC326E7EBBACCB6647BD427 (JSON::Fast) line 683
  in block <unit> at myjson.p6 line 9

Seems to only be an issue in hash keys, regular strings are ok

Stringification of a Buf is not done with 'Str'

I found this exception in my logs:

Died because of the exception:
    Stringification of a Buf is not done with 'Str'.
    The 'decode' method should be used to convert Buf to a Str.
      in sub from-json at /rw/home/dave/.rakubrew/versions/moar-2020.05.1/install/share/perl6/site/sources/CF9890C71AE8A56077B5CB316932D72C4F622655 (JSON::Fast) line 669
      in method get at /rw/home/dave/.rakubrew/versions/moar-2020.05.1/install/share/perl6/site/sources/9A32FD61B375BC9C16658D298F3EDFC0BF07B976 (Matrix::Client::Requester) line 29
      in method sync at /rw/home/dave/.rakubrew/versions/moar-2020.05.1/install/share/perl6/site/sources/21F88B5335208B63586F8168E3B6793E42ABEEE4 (Matrix::Client) line 183
      in method sync at /rw/home/dave/.rakubrew/versions/moar-2020.05.1/install/share/perl6/site/sources/21F88B5335208B63586F8168E3B6793E42ABEEE4 (Matrix::Client) line 178
      in block  at /rw/home/dave/.rakubrew/versions/moar-2020.05.1/install/share/perl6/site/sources/1DCA72658C23E63D648E8A1C9327A064E13175C3 (Matrix::Bot) line 97

I looked at the line it's complaining about but as I'm pretty new to Raku I've no idea what that does. Is this my issue or yours? :)

JSON::Fast fails to encode complex UTF

Given the following input:
{"update_id":109911583, "message":{"message_id":1228,"from":{"id":116204011,"is_bot":false,"first_name":"Someone","last_name":"Unknown \ud83c\udded\ud83c\uddf7","username":"s0me0ne","language_code":"en"},"chat":{"id":116204011,"first_name":"Someone","last_name":"Unknown \ud83c\udded\ud83c\uddf7","username":"s0me0ne","type":"private"},"date":1511035180,"text":"\u0444\u044b\u0432"}}

JSON::Fast::from-json produces an error:

Error encoding UTF-8 string: could not encode Unicode Surrogate codepoint 55356 (0xD83C)

While JSON::Tiny produces the correct result.

error when installing module

Im trying to install this module on Ubuntu version 20 and getting the following error. Any help would be appreciated.

:~/ronin/raku$ zef install https://github.com/timo/json_fast.git
===> Testing: JSON::Fast:ver<0.17>:authcpan:TIMOTIMO
[JSON::Fast] Cannot resolve caller subst(Str:D: Str:D, :global); none of these signatures match:
[JSON::Fast] (Str:D: Str:D $original, Str:D $final, *%options)
[JSON::Fast] (Str:D: $matcher, $replacement, *%options)
[JSON::Fast] in block at t/13-scopes.t line 6
===> Testing [FAIL]: JSON::Fast:ver<0.17>:authcpan:TIMOTIMO
Aborting due to test failure: JSON::Fast:ver<0.17>:authcpan:TIMOTIMO (use --force-test to override)

test files should not use 'lib'

causes double precomp on install and causes installation failure on windows.

any test harness will provide '-I.' when running

to-json incorrect encoding of new-line combiners

Consider

use JSON::Fast;
use Test;

is to-json("ab\rc"), '"ab\rc"';
is to-json("ab\nc"), '"ab\nc"';
is to-json("ab\r\nc"), '"ab\r\nc"';
lives-ok { from-json(to-json("ab\r\nc")) };

done-testing;

Produces:

$ perl6 /tmp/json-enc.t
ok 1 - 
ok 2 - 
not ok 3 - 

# Failed test at /tmp/tst.pl line 6
# expected: '"ab\r\nc"'
#      got: '"ab
c"'
not ok 4 - 

# Failed test at /tmp/tst.pl line 7
# at 4: the only whitespace allowed in json strings are spaces
1..4
# Looks like you failed 2 tests of 4

The "\r\n" sequence does not seem to encode correctly.

to-json() doesn't comply with newest JSON spec

The newest JSON spec—contrary to previous versions—does allow non-object/array things at the top level. Reference: http://rfc7159.net/rfc7159#rfc.section.2 (second paragraph, especially). This module's from-json, however, displays an error when attempting to decode JSON conforming to this newest spec:

$ perl6 -MJSON::Fast -e 'say from-json "42"'
a JSON string ought to be a list or an object
  in sub from-json at /home/zoffix/.rakudobrew/moar-nom/install/share/perl6/site/sources/2989569D47BA7B99ACBF76A588A4EE68EB30E3EB line 304
  in block <unit> at -e line 1

Weird testing error depending on the available testers

Refs: JJ/docker-raku-test#12 librasteve/raku-Physics-Constants#5

This is a weird error. zef test . works fine on the default installation, which uses the prove+ plugin:

===> Testing: JSON::Fast:ver<0.16>
[JSON::Fast] Testing with plugin: Zef::Service::Shell::prove+{<anon|1>}
[JSON::Fast] t/01-parse.t ...................... ok
[JSON::Fast] t/02-structure.t .................. ok
[JSON::Fast] t/03-unicode.t .................... ok
[JSON::Fast] t/04-roundtrip.t .................. ok
[JSON::Fast] t/05-unreasonable-requirements.t .. ok
[JSON::Fast] t/06-control-characters.t ......... ok
[JSON::Fast] t/07-datetime.t ................... ok
[JSON::Fast] t/08-sorted-keys.t ................ ok
[JSON::Fast] t/09-race.t ....................... ok
[JSON::Fast] t/10-multidocument.t .............. ok
[JSON::Fast] t/11-enum.t ....................... ok
[JSON::Fast] t/12-assocpositional.t ............ ok
[JSON::Fast] All tests successful.
[JSON::Fast] Files=12, Tests=546,  5 wallclock secs ( 0.05 usr  0.01 sys +  6.66 cusr  0.46 csys =  7.18 CPU)
[JSON::Fast] Result: PASS

However, it fails inmediately if you use TAP, which is what the test container uses:

/test $ zef --debug test .
===> Testing: JSON::Fast:ver<0.16>
[JSON::Fast] Testing with plugin: Zef::Service::TAP+{<anon|1>}
===> Testing [FAIL]: JSON::Fast:ver<0.16>
Aborting due to test failure: JSON::Fast:ver<0.16> (use --force-test to override)

I really have no idea why, or even where to start looking. It's not failing on other modules, just on this one.

to-json: option to specify sort-comparison block for keys

to-json: Would be fab if we could specify a sort-comparator for the keys, so that we could control the ordering of the keys in the output.

Given that keys can be multi-level, maybe make $a/$b strings contain the delimited parts of the parent keys - e.g. $a = "one\tgreen\tapple" means that this value is at "one": { "green" : "apple", ... etc. etc. depending on the internals.

This means that I could sort keys according to an arbitrary external priority - like whether an entry in my META6.json is required or optional, or I could even remember incoming JSON key order and write new JSON in the same order with new entries at the end - etc. etc.

Newline etc, escaping bug.

% perl6 -v
This is Rakudo version 2017.12-88-g8fd776fd7 built on MoarVM version 2017.12-15-g8414888b implementing Perl 6.c.
% perl6 -I ../json_fast/lib/ -MJSON::Fast -e'say from-json(q<"AB\nC">).perl'
"AB\nC"
% perl6 -I ../json_fast/lib/ -MJSON::Fast -e'say from-json(q<"AB\nC\u000A">).perl'
"ABnC\n"

Note the decoding of \n as n, but only if '\nand \u000A` are used together in a string.

New regression in JSON::Fast 0.9.9.

race conditions

Hi Timo,

I'm running into what seems to be a race condition of some sort. The code below illustrates the problem (note that this code works fine with e.g. JSON::Tiny) --

#!/usr/bin/env perl6

use JSON::Fast;

my $parseme = q:to/DONE/;
{ "a" : "1" }
{ "a" : "2" }
{ "a" : "3" }
{ "a" : "4" }
{ "a" : "5" }
{ "a" : "6" }
DONE

$parseme ~= $parseme for 1..10;

my @out = $parseme.lines
    .race(:degree(8),:batch(1))
    .map: { to-json( from-json($_) ); };

This is the error that occurs sometimes:

This type cannot unbox to a native string: P6opaque, Hash
  in sub str-escape at /usr/local/Cellar/rakudo-star/2017.04/share/perl6/site/sources/7F9536176FAF86BE6A849D6381F97144496BD662 (JSON::Fast) line 5
  in sub to-json at /usr/local/Cellar/rakudo-star/2017.04/share/perl6/site/sources/7F9536176FAF86BE6A849D6381F97144496BD662 (JSON::Fast) line 37
  in sub to-json at /usr/local/Cellar/rakudo-star/2017.04/share/perl6/site/sources/7F9536176FAF86BE6A849D6381F97144496BD662 (JSON::Fast) line 59
  in block  at json-faster.p6 line 18

build a little benchmark suite

ideally we'd have a suite of benchmarks that stress different parts of the parser. for example, i would assume it'd be good to have at least one benchmark that has no strings at all in it, since the string parser is so complex.

also, benchmarks for serializing json rather than just parsing would be nice.

can't install with zef, test failures

$ perl6 --version
This is Rakudo version 2016.12-223-g6d28c1d built on MoarVM version 2016.12-60-g36f3385
implementing Perl 6.c.
$ zef install JSON::Fast;
===> Searching for: JSON::Fast
===> Testing: JSON::Fast:ver('0.7')
t/01-parse.t ...... All 93 subtests passed
t/02-structure.t .. All 10 subtests passed
t/03-unicode.t .... All 4 subtests passed
t/04-roundtrip.t .. ok
All tests successful.

Test Summary Report
-------------------
-------------------
t/01-parse.t  (Wstat: 0 Tests: 75 Failed: 0)
  Parse errors: Tests out of sequence.  Found (13) but expected (12)
                Tests out of sequence.  Found (14) but expected (13)
                Tests out of sequence.  Found (15) but expected (14)
                Tests out of sequence.  Found (16) but expected (15)
                Tests out of sequence.  Found (17) but expected (16)
                Tests out of sequence.  Found (18) but expected (17)
                Tests out of sequence.  Found (19) but expected (18)
                Tests out of sequence.  Found (20) but expected (19)
                Tests out of sequence.  Found (21) but expected (20)
                Tests out of sequence.  Found (22) but expected (21)
                Tests out of sequence.  Found (23) but expected (22)
                Tests out of sequence.  Found (24) but expected (23)
                Tests out of sequence.  Found (25) but expected (24)
                Tests out of sequence.  Found (26) but expected (25)
                Tests out of sequence.  Found (27) but expected (26)
                Tests out of sequence.  Found (28) but expected (27)
                Tests out of sequence.  Found (29) but expected (28)
                Tests out of sequence.  Found (31) but expected (29)
                Tests out of sequence.  Found (34) but expected (30)
                Tests out of sequence.  Found (35) but expected (31)
                Tests out of sequence.  Found (36) but expected (32)
                Tests out of sequence.  Found (37) but expected (33)
                Tests out of sequence.  Found (38) but expected (34)
                Tests out of sequence.  Found (40) but expected (35)
                Tests out of sequence.  Found (41) but expected (36)
                Tests out of sequence.  Found (42) but expected (37)
                Tests out of sequence.  Found (43) but expected (38)
                Tests out of sequence.  Found (44) but expected (39)
                Tests out of sequence.  Found (45) but expected (40)
                Tests out of sequence.  Found (46) but expected (41)
                Tests out of sequence.  Found (47) but expected (42)
                Tests out of sequence.  Found (48) but expected (43)
                Tests out of sequence.  Found (54) but expected (44)
                Tests out of sequence.  Found (55) but expected (45)
                Tests out of sequence.  Found (56) but expected (46)
                Tests out of sequence.  Found (61) but expected (47)
                Tests out of sequence.  Found (62) but expected (48)
                Tests out of sequence.  Found (63) but expected (49)
                Tests out of sequence.  Found (64) but expected (50)
                Tests out of sequence.  Found (65) but expected (51)
                Tests out of sequence.  Found (66) but expected (52)
                Tests out of sequence.  Found (67) but expected (53)
                Tests out of sequence.  Found (68) but expected (54)
                Tests out of sequence.  Found (72) but expected (55)
                Tests out of sequence.  Found (73) but expected (56)
                Tests out of sequence.  Found (74) but expected (57)
                Tests out of sequence.  Found (75) but expected (58)
                Tests out of sequence.  Found (76) but expected (59)
                Tests out of sequence.  Found (77) but expected (60)
                Tests out of sequence.  Found (78) but expected (61)
                Tests out of sequence.  Found (79) but expected (62)
                Tests out of sequence.  Found (81) but expected (63)
                Tests out of sequence.  Found (82) but expected (64)
                Tests out of sequence.  Found (83) but expected (65)
                Tests out of sequence.  Found (84) but expected (66)
                Tests out of sequence.  Found (85) but expected (67)
                Tests out of sequence.  Found (86) but expected (68)
                Tests out of sequence.  Found (87) but expected (69)
                Tests out of sequence.  Found (88) but expected (70)
                Tests out of sequence.  Found (89) but expected (71)
                Tests out of sequence.  Found (90) but expected (72)
                Tests out of sequence.  Found (91) but expected (73)
                Tests out of sequence.  Found (92) but expected (74)
                Tests out of sequence.  Found (93) but expected (75)
                Bad plan.  You planned 93 tests but ran 75.
t/02-structure.t (Wstat: 0 Tests: 7 Failed: 0)
  Parse errors: Tests out of sequence.  Found (8) but expected (6)
                Tests out of sequence.  Found (9) but expected (7)
                Bad plan.  You planned 10 tests but ran 7.
t/03-unicode.t  (Wstat: 0 Tests: 2 Failed: 0)
  Parse errors: Tests out of sequence.  Found (2) but expected (1)
                Tests out of sequence.  Found (4) but expected (2)
                Bad plan.  You planned 4 tests but ran 2.
Files=4, Tests=103,  5 wallclock secs
Result: FAILED

JSON::Fast can't roundtrip

Try saving data (to-json) with a string like this:

Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘

And then reading it back (from-json).

You'll get:

Couldn't decode hexadecimal unicode escape \uD83D\uDC69‍

Please tag releases to help Debian packaging

Hello

To help packaging activities in Debian distribution (and probably others), could you please create tags and publish them on github so we, packagers can have something to latch on ?

Otherwise, I'll have to a package version based on a (rather arbitrary) date (e.g. perl6-json-fast-2016.04.19-1).

All the best

thread safety issues caused by underlying rakudo bug

I believe this library's to-json function is affected by https://rt.perl.org/Public/Bug/Display.html?id=131985. While that's clearly a Rakudo bug, it'd be nice if JSON::Fast worked around it.

Repro:

#!/usr/bin/env perl6

use v6.c;

use JSON::Fast;

await((1 .. 5).map: -> $tid {
   start {
      for (1 .. 100) -> $index {
         my $str = to-json { 'tid' => $tid.Str, 'index' => $index.Str }, :pretty;
         say "$tid   ??? $str" unless $str ~~ /\"tid\"\:\s\"$tid\"/;
         say "$index ??? $str" unless $str ~~ /\"index\"\:\s\"$index\"/;
      }
   }
});

produces output like:

72 ??? {
  "tid": "2",
  "index": "69"
}
1   ??? {
  "tid": "4",
  "index": "73"
}
79 ??? {
  "tid": "4",
  "index": "73"
}

The workaround is to not use {} interpolation until it's fixed upstream; at a glance, https://github.com/timo/json_fast/blob/master/lib/JSON/Fast.pm#L62 and https://github.com/timo/json_fast/blob/master/lib/JSON/Fast.pm#L39 are affected.

from-json: preserving order in objects/hashes

It would be really handy for many small modifications of large json files to be able to preserve the incoming order in the imported hashes to facilitate the following export back to json. Would it be possible by using ArrayHash Hash::Ordered or something? I am sorry that I'm not able to send a useful PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.