Skip to content
Browse files

Implement RFC7159. Closes #22

  • Loading branch information...
1 parent c75a04c commit 988832977173057496719704a1e7fb01d08d389d @moritz committed
Showing with 6 additions and 3 deletions.
  1. +3 −0 README
  2. +1 −1 lib/JSON/Tiny/Actions.pm
  3. +1 −1 lib/JSON/Tiny/Grammar.pm
  4. +1 −1 t/01-parse.t
View
3 README
@@ -4,6 +4,9 @@ A simple Perl 6 module for serializing and deserializing JSON.
say from-json('{ "a": 42 }').perl;
say to-json { a => [1, 2, 'b'] };
+JSON::Tiny implements RFC7159, which is a superset of ECMA-404, in that it
+permits any value as a top-level JSON string, not just arrays and objects.
+
All files (unless noted otherwise) can be used, modified and redistributed
under the terms of the Artistic License Version 2. Examples (in the
documentation, in tests or distributed as separate files) can be considered
View
2 lib/JSON/Tiny/Actions.pm
@@ -1,7 +1,7 @@
unit class JSON::Tiny::Actions;
method TOP($/) {
- make $/.values.[0].made;
+ make $<value>.made;
};
method object($/) {
make $<pairlist>.made.hash.item;
View
2 lib/JSON/Tiny/Grammar.pm
@@ -1,7 +1,7 @@
use v6;
unit grammar JSON::Tiny::Grammar;
-token TOP { ^ \s* [ <object> | <array> ] \s* $ }
+token TOP { \s* <value> \s* }
rule object { '{' ~ '}' <pairlist> }
rule pairlist { <pair> * % \, }
rule pair { <string> ':' <value> }
View
2 t/01-parse.t
@@ -143,6 +143,7 @@ my @t =
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}}>>,
+ Q<<"As of RFC 7159, a bare literal can be a JSON string too.">>,
;
my @n =
@@ -151,7 +152,6 @@ my @n =
'{ 3 : tru }', # not quite true
'{ "a : false }', # missing quote
# stolen from JSON::XS, 18_json_checker.t
- Q<<"A JSON payload should be an object or array, not a string.">>,
Q<<{"Extra value after close": true} "misplaced quoted value">>,
Q<<{"Illegal expression": 1 + 2}>>,
Q<<{"Illegal invocation": alert()}>>,

0 comments on commit 9888329

Please sign in to comment.
Something went wrong with that request. Please try again.