summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgregor herrmann <gregoa@debian.org>2021-01-30 19:49:58 +0100
committergregor herrmann <gregoa@debian.org>2021-01-30 19:49:58 +0100
commit31878b0fbeecc3ce85a502024609718fd8d93bf9 (patch)
tree12a1709fded6fbe9b2bc6c5808f8d01f085ae633
parent4441e009ac37b3d41dd39800a22e2af77598e434 (diff)
New upstream version 0.60
-rw-r--r--Changes9
-rw-r--r--MANIFEST8
-rw-r--r--MANIFEST.SKIP12
-rw-r--r--META.json7
-rw-r--r--META.yml6
-rw-r--r--Makefile.PL11
-rw-r--r--Parse.xs (renamed from Json3.xs)13
-rw-r--r--README12
-rw-r--r--examples/collide.pl2
-rw-r--r--examples/json-tiny-round-trip-demo.pl12
-rwxr-xr-xexamples/tokenize-synopsis.pl3
-rw-r--r--examples/true-subs.pl2
-rw-r--r--examples/whitespace-synopsis.pl22
-rw-r--r--json-whitespace.c9
-rw-r--r--lib/JSON/Parse.pm55
-rw-r--r--lib/JSON/Parse.pod214
-rw-r--r--lib/JSON/Tokenize.pm12
-rw-r--r--lib/JSON/Tokenize.pod84
-rw-r--r--lib/JSON/Whitespace.pm26
-rw-r--r--lib/JSON/Whitespace.pod83
-rw-r--r--see-also-info.json499
-rw-r--r--t/JPT.pm33
-rw-r--r--t/JSON-Parse.t32
-rw-r--r--t/Json3.t9
-rw-r--r--t/array.t7
-rw-r--r--t/bugzilla-2049.t8
-rw-r--r--t/collision.t25
-rw-r--r--t/json-tokenize.t15
-rw-r--r--t/kolmorogov42-1.t20
-rw-r--r--t/max-depth.t22
-rw-r--r--t/minify.t37
-rw-r--r--t/numbers.t28
-rw-r--r--t/object.t14
-rw-r--r--t/perl-monks-1165399.t19
-rw-r--r--t/read-file.t11
-rw-r--r--t/rfc7159.t18
-rw-r--r--[-rwxr-xr-x]t/string-bug-44.json0
-rw-r--r--[-rwxr-xr-x]t/string-bug-44.t12
-rw-r--r--t/syntax.t7
-rw-r--r--t/test-empty-string.t7
-rw-r--r--t/unicode.t15
-rw-r--r--t/utf8.t12
-rw-r--r--t/valid-json.t7
-rw-r--r--t/whitespace.t8
44 files changed, 633 insertions, 834 deletions
diff --git a/Changes b/Changes
index ea8e52b..ed103b1 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,11 @@
-0.59 2021-01-04
+0.60 2021-01-26
+
+* Add "read" method to read a file from an object
+* Rename "run" to "parse" (old name is still OK)
+* "tokenize_child" no longer returns parent on failure
+* Add JSON::Whitespace (manipulate JSON whitespace) to the module
+
+0.59 2021-01-26
* "json_file_to_perl" renamed "read_json"
* Documentation work
diff --git a/MANIFEST b/MANIFEST
index dc2a250..45d0572 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -19,29 +19,33 @@ examples/synopsis.pl
examples/tokenize-synopsis.pl
examples/true-subs.pl
examples/unicode-details.pl
+examples/whitespace-synopsis.pl
json-common.c
json-entry-points.c
json-perl.c
json-whitespace.c
-Json3.xs
lib/JSON/Parse.pm
lib/JSON/Parse.pod
lib/JSON/Tokenize.pm
lib/JSON/Tokenize.pod
+lib/JSON/Whitespace.pm
+lib/JSON/Whitespace.pod
Makefile.PL
MANIFEST This list of files
MANIFEST.SKIP
+Parse.xs
README
script/validjson
-see-also-info.json
t/array.t
t/bugzilla-2049.t
t/collision.t
+t/JPT.pm
t/JSON-Parse.t
t/json-tokenize.t
t/Json3.t
t/kolmorogov42-1.t
t/max-depth.t
+t/minify.t
t/numbers.t
t/object.t
t/perl-monks-1165399.t
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
index 3289b0b..47d739b 100644
--- a/MANIFEST.SKIP
+++ b/MANIFEST.SKIP
@@ -8,7 +8,7 @@ MYMETA..*
.*\.bak
^Json3-[0-9.]/$
^Json3-[0-9.]\.tar\.gz$
-^Json3.(?:c|o|bs)$
+^Parse.(?:c|o|bs)$
^peek\.pl$
^test-empty-string\.pl$
^xt/.*
@@ -42,21 +42,19 @@ benchmarks
^doc/.*$
#
^examples/.*-out\.txt$
-# Experimental unfinished module should not go to CPAN
-^lib/JSON/Whitespace\.pm$
# Template for POD
^lib/JSON/Tokenize\.pod\.tmpl$
+^lib/JSON/Whitespace\.pod\.tmpl$
# Obsolete files
^obsolete/.*$
-# Files which are so that the distribution can be built from the
-# github repository rather than the CPAN distribution file.
-^copy\.pl$
-^copied/.*$
# Author version change script
^versionup\.pl$
# CI control files
^\.travis\.yml$
^build/.*$
+# These are used to make the documentation.
+^see-also-info\.json$
+^modules\.pl$
# Local variables:
# comment-start: "#"
# End:
diff --git a/META.json b/META.json
index 532276a..ae1c4ff 100644
--- a/META.json
+++ b/META.json
@@ -17,6 +17,11 @@
"directory" : [
"t",
"inc"
+ ],
+ "file" : [
+ "build/JPB.pm",
+ "t/JPT.pm",
+ "xt/JPXT.pm"
]
},
"prereqs" : {
@@ -48,6 +53,6 @@
"web" : "https://github.com/benkasminbullock/JSON-Parse"
}
},
- "version" : "0.59",
+ "version" : "0.60",
"x_serialization_backend" : "JSON::PP version 4.04"
}
diff --git a/META.yml b/META.yml
index e7b0d0e..ec678cd 100644
--- a/META.yml
+++ b/META.yml
@@ -17,11 +17,15 @@ no_index:
directory:
- t
- inc
+ file:
+ - build/JPB.pm
+ - t/JPT.pm
+ - xt/JPXT.pm
requires:
Carp: '0'
perl: '5.008009'
resources:
bugtracker: https://github.com/benkasminbullock/JSON-Parse/issues
repository: git://github.com/benkasminbullock/JSON-Parse.git
-version: '0.59'
+version: '0.60'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
diff --git a/Makefile.PL b/Makefile.PL
index 30d022d..ba0df3b 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -30,10 +30,17 @@ WriteMakefile (
web => "$repo/issues",
},
},
+ no_index => {
+ file => [
+ 'build/JPB.pm',
+ 't/JPT.pm',
+ 'xt/JPXT.pm',
+ ],
+ },
},
- # All the C files are actually #included into Json3.xs so there is
+ # All the C files are actually #included into Parse.xs so there is
# only one object file.
- OBJECT => 'Json3.o',
+ OBJECT => 'Parse.o',
# Currently the oldest version to pass at CPAN testers.
# http://matrix.cpantesters.org/?dist=JSON-Parse+0.24
MIN_PERL_VERSION => '5.008009',
diff --git a/Json3.xs b/Parse.xs
index 6bb8669..0425554 100644
--- a/Json3.xs
+++ b/Parse.xs
@@ -240,7 +240,7 @@ OUTPUT:
JSON::Tokenize tokenize_child (token)
JSON::Tokenize token
CODE:
- RETVAL = token;
+ RETVAL = 0;
if (token->child) {
RETVAL = token->child;
RETVAL->blessed = 1;
@@ -296,12 +296,11 @@ CODE:
tokenize_free (token);
MODULE=JSON::Parse PACKAGE=JSON::Whitespace
-
+
SV * strip_whitespace (tokens, json)
- JSON::Tokenize tokens;
- SV * json;
+ JSON::Tokenize tokens;
+ SV * json;
CODE:
- RETVAL = strip_whitespace (tokens, json);
+ RETVAL = strip_whitespace (tokens, json);
OUTPUT:
- RETVAL
-
+ RETVAL
diff --git a/README b/README
index 8350131..eec123c 100644
--- a/README
+++ b/README
@@ -6,7 +6,7 @@
-This is the README for JSON::Parse version 0.59.
+This is the README for JSON::Parse version 0.60.
JSON::Parse is a "module" for the Perl computer programming language, a
library of computer code to install on a computer. This document contains
@@ -39,7 +39,7 @@ file, and there is a safer version of "parse_json" called
"parse_json_safe" which doesn't throw exceptions.
For special cases of parsing, there are also methods "new" and
-"run", which create a JSON parsing object and run it on text. See
+"parse", which create a JSON parsing object and run it on text. See
"METHODS".
JSON::Parse accepts only UTF-8 as input. See "UTF-8 only" and
@@ -75,11 +75,11 @@ If you have the App::cpanminus installer, you may prefer
cpanm JSON::Parse
-To install the module from the source file, JSON-Parse-0.59.tar.gz, follow
+To install the module from the source file, JSON-Parse-0.60.tar.gz, follow
this sequence of commands:
- tar xfz JSON-Parse-0.59.tar.gz
- cd JSON-Parse-0.59
+ tar xfz JSON-Parse-0.60.tar.gz
+ cd JSON-Parse-0.60
perl Makefile.PL
make
make install
@@ -104,6 +104,6 @@ repository on github at
-----------------------------------------------------------------------------
-This README was written on Mon Jan 4 08:47:42 2021.
+This README was written on Tue Jan 26 08:59:04 2021.
-----------------------------------------------------------------------------
diff --git a/examples/collide.pl b/examples/collide.pl
index d48e21c..e5c23c6 100644
--- a/examples/collide.pl
+++ b/examples/collide.pl
@@ -5,6 +5,6 @@ use JSON::Parse;
my $jp = JSON::Parse->new ();
$jp->detect_collisions (1);
eval {
- $jp->run ('{"animals":{"cat":"moggy","cat":"feline","cat":"neko"}}');
+ $jp->parse ('{"animals":{"cat":"moggy","cat":"feline","cat":"neko"}}');
};
print "$@\n" if $@;
diff --git a/examples/json-tiny-round-trip-demo.pl b/examples/json-tiny-round-trip-demo.pl
index 99747e6..12527a9 100644
--- a/examples/json-tiny-round-trip-demo.pl
+++ b/examples/json-tiny-round-trip-demo.pl
@@ -11,25 +11,25 @@ my $jp = JSON::Parse->new ();
my $jc = JSON::Create->new (sort => 1);
print "First do a round-trip of our modules:\n\n";
-print $jc->run ($jp->run ($cream)), "\n\n";
+print $jc->create ($jp->parse ($cream)), "\n\n";
print "Now do a round-trip of JSON::Tiny:\n\n";
print encode_json (decode_json ($cream)), "\n\n";
print "🥴 First, incompatible mode:\n\n";
-print 'tiny(parse): ', encode_json ($jp->run ($cream)), "\n";
-print 'create(tiny): ', $jc->run (decode_json ($cream)), "\n\n";
+print 'tiny(parse): ', encode_json ($jp->parse ($cream)), "\n";
+print 'create(tiny): ', $jc->create (decode_json ($cream)), "\n\n";
# Set our parser to produce these things as literals:
$jp->set_true (JSON::Tiny::true);
$jp->set_false (JSON::Tiny::false);
print "🔄 Compatibility with JSON::Parse:\n\n";
-print 'tiny(parse):', encode_json ($jp->run ($cream)), "\n\n";
+print 'tiny(parse):', encode_json ($jp->parse ($cream)), "\n\n";
$jc->bool ('JSON::Tiny::_Bool');
print "🔄 Compatibility with JSON::Create:\n\n";
-print 'create(tiny):', $jc->run (decode_json ($cream)), "\n\n";
+print 'create(tiny):', $jc->create (decode_json ($cream)), "\n\n";
print "🔄 JSON::Parse and JSON::Create are still compatible too:\n\n";
-print $jc->run ($jp->run ($cream)), "\n";
+print $jc->create ($jp->parse ($cream)), "\n";
diff --git a/examples/tokenize-synopsis.pl b/examples/tokenize-synopsis.pl
index 2149c36..7b3fa68 100755
--- a/examples/tokenize-synopsis.pl
+++ b/examples/tokenize-synopsis.pl
@@ -2,6 +2,7 @@
use warnings;
use strict;
use JSON::Tokenize ':all';
+
my $input = '{"tuttie":["fruity", true, 100]}';
my $token = tokenize_json ($input);
print_tokens ($token, 0);
@@ -15,7 +16,7 @@ sub print_tokens
my $type = tokenize_type ($token);
print " " x $depth;
my $value = substr ($input, $start, $end - $start);
- print ">>$value<< has type $type\n";
+ print "'$value' has type '$type'.\n";
my $child = tokenize_child ($token);
if ($child) {
print_tokens ($child, $depth+1);
diff --git a/examples/true-subs.pl b/examples/true-subs.pl
index a577fca..1b93439 100644
--- a/examples/true-subs.pl
+++ b/examples/true-subs.pl
@@ -5,6 +5,6 @@ use JSON::Parse;
my $json = '{"yes":true,"no":false}';
my $jp = JSON::Parse->new ();
$jp->set_true ('Yes, that is so true');
-my $out = $jp->run ($json);
+my $out = $jp->parse ($json);
print $out->{yes}, "\n";
diff --git a/examples/whitespace-synopsis.pl b/examples/whitespace-synopsis.pl
new file mode 100644
index 0000000..f2c1798
--- /dev/null
+++ b/examples/whitespace-synopsis.pl
@@ -0,0 +1,22 @@
+use warnings;
+use strict;
+use JSON::Whitespace ':all';
+
+my $in = <<EOF;
+{
+ "animals":{
+ "kingkong":"🦍"
+ },
+ "baka":[
+ "ドジ"
+ ],
+ "fruit":{
+ "grape":"🍇"
+ },
+ "moons":{
+ "🌑":0
+ }
+ }
+EOF
+my $minify = json_minify ($in);
+print $minify;
diff --git a/json-whitespace.c b/json-whitespace.c
index 2957da1..039900c 100644
--- a/json-whitespace.c
+++ b/json-whitespace.c
@@ -1,8 +1,17 @@
/* Type for adding whitespace. */
+typedef struct json_s {
+ SV * sv;
+ char * s;
+ STRLEN sl;
+}
+json_s_t;
+
typedef struct json_ws {
SV * news;
SV * olds;
+ /* Length of original string. */
+ STRLEN olds_l;
/* Length of new string. */
unsigned int news_l;
/* Copy point. */
diff --git a/lib/JSON/Parse.pm b/lib/JSON/Parse.pm
index f427733..bab90e1 100644
--- a/lib/JSON/Parse.pm
+++ b/lib/JSON/Parse.pm
@@ -1,7 +1,9 @@
package JSON::Parse;
+use warnings;
+use strict;
require Exporter;
-@ISA = qw(Exporter);
-@EXPORT_OK = qw/
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw/
assert_valid_json
json_file_to_perl
json_to_perl
@@ -12,13 +14,11 @@ require Exporter;
validate_json
/;
-%EXPORT_TAGS = (
+our %EXPORT_TAGS = (
all => \@EXPORT_OK,
);
-use warnings;
-use strict;
use Carp;
-our $VERSION = '0.59';
+our $VERSION = '0.60';
require XSLoader;
XSLoader::load (__PACKAGE__, $VERSION);
@@ -65,9 +65,35 @@ sub validate_json
goto &assert_valid_json;
}
+sub read_file
+{
+ my ($file_name) = @_;
+ if (! -f $file_name) {
+ # Trap possible errors from "open" before getting there.
+ croak "File does not exist: '$file_name'";
+ }
+ my $json = '';
+ open my $in, "<:encoding(utf8)", $file_name
+ or croak "Error opening $file_name: $!";
+ while (<$in>) {
+ $json .= $_;
+ }
+ close $in or croak $!;
+ return $json;
+}
+
+sub JSON::Parse::read
+{
+ my ($jp, $file_name) = @_;
+ my $json = read_file ($file_name);
+ return $jp->parse ($json);
+}
+
sub read_json
{
- goto &json_file_to_perl;
+ my ($file_name) = @_;
+ my $json = read_file ($file_name);
+ return parse_json ($json);
}
sub valid_json
@@ -85,15 +111,7 @@ sub valid_json
sub json_file_to_perl
{
- my ($file_name) = @_;
- my $json = '';
- open my $in, "<:encoding(utf8)", $file_name
- or croak "Error opening $file_name: $!";
- while (<$in>) {
- $json .= $_;
- }
- close $in or croak $!;
- return parse_json ($json);
+ goto &read_json;
}
sub run
@@ -114,4 +132,9 @@ sub run
}
}
+sub parse
+{
+ goto &run;
+}
+
1;
diff --git a/lib/JSON/Parse.pod b/lib/JSON/Parse.pod
index a006a08..7217a02 100644
--- a/lib/JSON/Parse.pod
+++ b/lib/JSON/Parse.pod
@@ -23,8 +23,8 @@ Convert JSON into Perl.
=head1 VERSION
-This documents version 0.59 of JSON::Parse corresponding to
-L<git commit e10440285845d6b0f29746bce84c6b546e557f6f|https://github.com/benkasminbullock/JSON-Parse/commit/e10440285845d6b0f29746bce84c6b546e557f6f> released on Mon Jan 4 08:46:00 2021 +0900.
+This documents version 0.60 of JSON::Parse corresponding to
+L<git commit 27b70e98176290ddd145cadfe8aa6ff43bb71703|https://github.com/benkasminbullock/JSON-Parse/commit/27b70e98176290ddd145cadfe8aa6ff43bb71703> released on Tue Jan 26 08:51:47 2021 +0900.
@@ -43,7 +43,7 @@ file, and there is a safer version of L</parse_json> called
L</parse_json_safe> which doesn't throw exceptions.
For special cases of parsing, there are also methods L</new> and
-L</run>, which create a JSON parsing object and run it on text. See
+L</parse>, which create a JSON parsing object and run it on text. See
L</METHODS>.
JSON::Parse accepts only UTF-8 as input. See L</UTF-8 only> and
@@ -66,11 +66,11 @@ L</Handling of Unicode>.
produces output
- Your JSON was invalid: JSON error at line 1, byte 7/11: Unexpected character ':' parsing array starting from byte 1: expecting whitespace: '\n', '\r', '\t', ' ' or comma: ',' or end of array: ']' at /usr/home/ben/projects/Json3/examples/assert.pl line 6.
+ Your JSON was invalid: JSON error at line 1, byte 7/11: Unexpected character ':' parsing array starting from byte 1: expecting whitespace: 'n', '\r', '\t', ' ' or comma: ',' or end of array: ']' at /usr/home/ben/projects/json-parse/examples/assert.pl line 6.
-(This example is included as L<F<assert.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.59/examples/assert.pl> in the distribution.)
+(This example is included as L<F<assert.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.60/examples/assert.pl> in the distribution.)
This is the underlying function for L</valid_json>. It runs at the
@@ -82,6 +82,8 @@ This cannot detect key collisions in the JSON since it does not store
values. See L</Key collisions> for more on this module's handling of
non-unique names in the JSON.
+The method equivalent to this is L</check>.
+
The behaviour of disallowing empty inputs was changed in version
0.49.
@@ -113,7 +115,7 @@ produces output
HASH
-(This example is included as L<F<hash.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.59/examples/hash.pl> in the distribution.)
+(This example is included as L<F<hash.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.60/examples/hash.pl> in the distribution.)
If the input JSON text is a serialized array, an array reference is
@@ -131,7 +133,7 @@ produces output
ARRAY
-(This example is included as L<F<array.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.59/examples/array.pl> in the distribution.)
+(This example is included as L<F<array.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.60/examples/array.pl> in the distribution.)
Otherwise a Perl scalar is returned.
@@ -142,7 +144,8 @@ JSON. The behaviour of disallowing empty inputs was changed in version
0.49.
The function L</parse_json_safe> offers a version of this function
-with various safety features enabled.
+with various safety features enabled. The method L</parse> is
+equivalent to this.
=head2 parse_json_safe
@@ -197,8 +200,10 @@ L</parse_json>.
This is exactly the same as L</parse_json> except that it reads the
JSON from the specified file rather than a scalar. The file must be in
the UTF-8 encoding, and is opened as a character file using
-C<:encoding(UTF-8)> (see L<PerlIO::encoding> and L<perluniintro> for
-details). The output is marked as character strings.
+C<:encoding(utf8)> (see L<PerlIO::encoding> and L<perluniintro>). The
+output is marked as character strings.
+
+The method equivalent is L</read>.
This is a convenience function written in Perl. You may prefer to read
the file yourself using another module if you need faster performance.
@@ -221,24 +226,28 @@ rather than storing it into Perl variables.
This does not supply the actual errors which caused invalidity. Use
L</assert_valid_json> to get error messages when the JSON is invalid.
-This cannot detect key collisions in the JSON since it does not store
-values. See L</Key collisions> for more on this module's handling of
-non-unique names in the JSON.
+This cannot detect duplicate keys in JSON objects because it does not
+store values. See L</Key collisions> for more on this module's
+handling of non-unique names in the JSON.
=head1 METHODS
If you need to parse JSON and you are not satisfied with the parsing
options offered by L</parse_json> and L</parse_json_safe>, you can
create a JSON parsing object with L</new> and set various options on
-the object, then use it with L</run>. These options include the
-ability to copy JSON literals with L</copy_literals>, switch off fatal
-errors with L</warn_only>, detect key collisions in objects with
-L</detect_collisions>, and set the JSON literals to user defined
-values with the methods described under L</Methods for manipulating
-literals>.
+the object, then use it with L</parse> or L</read>.
+
+There are options to copy JSON literals (C<true>, C<false>, C<null>)
+with L</copy_literals>, switch off fatal errors with L</warn_only>,
+detect duplicate keys in objects with L</detect_collisions>, set the
+maximum depth of nested objects and arrays with L</set_max_depth>,
+produce machine-readable parsing errors with L</diagnostics_hash>, and
+set the JSON literals to user defined values with the methods
+described under L</Methods for manipulating literals>.
-These methods only work on an object created with L</new>; they do not
-affect the behaviour of L</parse_json> or L</parse_json_safe>.
+These methods only affect the object created with L</new>; they do not
+globally affect the behaviour of L</parse_json> or
+L</parse_json_safe>.
=head2 check
@@ -287,18 +296,18 @@ byte position where the start of the colliding string was found:
my $jp = JSON::Parse->new ();
$jp->detect_collisions (1);
eval {
- $jp->run ('{"animals":{"cat":"moggy","cat":"feline","cat":"neko"}}');
+ $jp->parse ('{"animals":{"cat":"moggy","cat":"feline","cat":"neko"}}');
};
print "$@\n" if $@;
produces output
- JSON error at line 1, byte 28/55: Name is not unique: "cat" parsing object starting from byte 12 at /usr/home/ben/projects/Json3/blib/lib/JSON/Parse.pm line 103.
+ JSON error at line 1, byte 28/55: Name is not unique: "cat" parsing object starting from byte 12 at /usr/home/ben/projects/json-parse/examples/../blib/lib/JSON/Parse.pm line 131.
-(This example is included as L<F<collide.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.59/examples/collide.pl> in the distribution.)
+(This example is included as L<F<collide.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.60/examples/collide.pl> in the distribution.)
The C<detect_collisions (1)> behaviour is the behaviour of
@@ -312,8 +321,8 @@ behaviour of L</parse_json>.
$jp->diagnostics_hash (1);
This changes diagnostics produced by errors from a simple string into
-a hash reference containing various fields. This is experimental and
-subject to change. This is incompatible with L</warn_only>.
+a hash reference containing various fields. This is incompatible with
+L</warn_only>.
This replaces the previous experimental global variable
C<$json_diagnostics>, which was removed from the module. The hash keys
@@ -323,6 +332,9 @@ which returns the usual error.
This requires Perl version 5.14 or later.
+An example of the use of this method to "repair" broken JSON is in the
+module L</JSON::Repair>.
+
🎲 This method was added in version 0.46.
=head2 get_max_depth
@@ -342,15 +354,26 @@ Create a new JSON::Parse object.
🎲 This method was added in version 0.38.
-=head2 run
+=head2 parse
- my $out = $jp->run ($json);
+ my $out = $jp->parse ($json);
This does the same thing as L</parse_json>, except its behaviour can
be modified using the methods below.
🎲 This method was added in version 0.38.
+This was renamed from C<run> in version 0.60.
+
+=head2 read
+
+ my $json = $jp->read ($file);
+
+Read a file, parse the contained JSON, and return the output. This
+method is equivalent to the function L</read_json>.
+
+🎲 This method was added in version 0.60.
+
=head2 set_max_depth
$jp->set_max_depth (42);
@@ -408,7 +431,7 @@ scalar:
my $json = '{"yes":true,"no":false}';
my $jp = JSON::Parse->new ();
$jp->set_true ('Yes, that is so true');
- my $out = $jp->run ($json);
+ my $out = $jp->parse ($json);
print $out->{yes}, "\n";
@@ -553,6 +576,10 @@ This is exactly the same function as L</read_json>. The function was
renamed in version 0.59, after the same function in
L</File::JSON::Slurper>.
+=head2 run
+
+This is the old name for L</parse>.
+
=head2 validate_json
This is exactly the same function as L</assert_valid_json>.
@@ -583,6 +610,19 @@ mapped to the equivalent ASCII character.
Inputs must be in the UTF-8 format. See L</UTF-8 only>.
+In addition, JSON::Parse rejects UTF-8 which encodes non-characters
+such as C<U+FFFF> and ill-formed characters such as incomplete halves
+of surrogate pairs.
+
+Unicode encoding points in the input of the form C<\u3000> are
+converted into the equivalent UTF-8 bytes.
+
+Surrogate pairs in the form C<\uD834\uDD1E> are also handled. If the
+second half of the surrogate pair is missing, an L</Unexpected
+character> or L</Unexpected end of input> error is thrown. If the
+second half of the surrogate pair is present but contains an
+impossible value, a L</Not surrogate pair> error is thrown.
+
If the input to L</parse_json> is marked as Unicode characters, the
output strings will be marked as Unicode characters. If the input is
not marked as Unicode characters, the output strings will not be
@@ -688,7 +728,7 @@ produces output
Native Perl: かあ
-(This example is included as L<F<unicode-details.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.59/examples/unicode-details.pl> in the distribution.)
+(This example is included as L<F<unicode-details.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.60/examples/unicode-details.pl> in the distribution.)
Although in general the above would be an unsafe practice, JSON::Parse
@@ -699,12 +739,6 @@ L</UTF-8 only>. Doing things this way, rather than the way that Perl
does it, was one of the original motivations for writing this
module.
-Surrogate pairs in the form C<\uD834\uDD1E> are also handled. If the
-second half of the surrogate pair is missing, an L</Unexpected
-character> or L</Unexpected end of input> error is thrown. If the
-second half of the surrogate pair is present but contains an
-impossible value, a L</Not surrogate pair> error is thrown.
-
=head2 JSON arrays
JSON arrays become Perl array references. The elements of the Perl
@@ -757,11 +791,11 @@ A key collision is something like the following.
produces output
- JSON::Parse::parse_json_safe: JSON error at line 1, byte 10/14: Name is not unique: "a" parsing object starting from byte 1 at /usr/home/ben/projects/Json3/examples/key-collision.pl line 8.
+ JSON::Parse::parse_json_safe: Name is not unique: "a" parsing object starting from byte 1 at /usr/home/ben/projects/json-parse/examples/key-collision.pl line 8.
Ambiguous key 'a' is 2
-(This example is included as L<F<key-collision.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.59/examples/key-collision.pl> in the distribution.)
+(This example is included as L<F<key-collision.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.60/examples/key-collision.pl> in the distribution.)
Here the key "a" could be either 1 or 2. As seen in the example,
@@ -837,28 +871,28 @@ version 0.58:
my $jc = JSON::Create->new (sort => 1);
print "First do a round-trip of our modules:\n\n";
- print $jc->run ($jp->run ($cream)), "\n\n";
+ print $jc->create ($jp->parse ($cream)), "\n\n";
print "Now do a round-trip of JSON::Tiny:\n\n";
print encode_json (decode_json ($cream)), "\n\n";
print "🥴 First, incompatible mode:\n\n";
- print 'tiny(parse): ', encode_json ($jp->run ($cream)), "\n";
- print 'create(tiny): ', $jc->run (decode_json ($cream)), "\n\n";
+ print 'tiny(parse): ', encode_json ($jp->parse ($cream)), "\n";
+ print 'create(tiny): ', $jc->create (decode_json ($cream)), "\n\n";
# Set our parser to produce these things as literals:
$jp->set_true (JSON::Tiny::true);
$jp->set_false (JSON::Tiny::false);
print "🔄 Compatibility with JSON::Parse:\n\n";
- print 'tiny(parse):', encode_json ($jp->run ($cream)), "\n\n";
+ print 'tiny(parse):', encode_json ($jp->parse ($cream)), "\n\n";
$jc->bool ('JSON::Tiny::_Bool');
print "🔄 Compatibility with JSON::Create:\n\n";
- print 'create(tiny):', $jc->run (decode_json ($cream)), "\n\n";
+ print 'create(tiny):', $jc->create (decode_json ($cream)), "\n\n";
print "🔄 JSON::Parse and JSON::Create are still compatible too:\n\n";
- print $jc->run ($jp->run ($cream)), "\n";
+ print $jc->create ($jp->parse ($cream)), "\n";
produces output
@@ -889,7 +923,7 @@ produces output
{"clapton":true,"hendrix":false}
-(This example is included as L<F<json-tiny-round-trip-demo.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.59/examples/json-tiny-round-trip-demo.pl> in the distribution.)
+(This example is included as L<F<json-tiny-round-trip-demo.pl>|https://fastapi.metacpan.org/source/BKB/JSON-Parse-0.60/examples/json-tiny-round-trip-demo.pl> in the distribution.)
Most of the other CPAN modules use similar methods to L<JSON::Tiny>,
@@ -972,10 +1006,9 @@ diligently verified.
=item UTF-8 only
-Although JSON may come in various encodings of Unicode, JSON::Parse
-only parses the UTF-8 format. If input is in a different Unicode
-encoding than UTF-8, convert the input before handing it to this
-module. For example, for the UTF-16 format,
+JSON::Parse only parses the UTF-8 format. If input is in a different
+Unicode encoding than UTF-8, convert the input before handing it to
+this module. For example, for the UTF-16 format,
use Encode 'decode';
my $input_utf8 = decode ('UTF-16', $input);
@@ -988,8 +1021,8 @@ L<perluniintro>):
JSON::Parse does not try to determine the nature of the octet stream
using BOM markers. A BOM marker in the input consists of bytes C<0xFE>
-and C<0xFF> which are invalid as UTF-8, and thus will cause a fatal
-error.
+and C<0xFF>, both of which are invalid as UTF-8, and thus will cause a
+fatal error.
This restriction to UTF-8 applies regardless of whether Perl thinks
that the input string is a character string or a byte
@@ -1229,7 +1262,7 @@ L</detect_collisions>. For example an input like
gives output
- JSON error at line 1, byte 23/31: Name is not unique: "hocus" parsing object starting from byte 1 at blib/lib/JSON/Parse.pm line 113.
+ JSON error at line 1, byte 23/31: Name is not unique: "hocus" parsing object starting from byte 1 at blib/lib/JSON/Parse.pm line 131.
@@ -1298,8 +1331,8 @@ able to fully work out the reason behind the better speed.
There is some benchmarking code in the github repository under the
directory "benchmarks" for those wishing to test these claims. The
-script L<F<benchmarks/bench>|https://github.com/benkasminbullock/JSON-Parse/e10440285845d6b0f29746bce84c6b546e557f6f/benchmarks/bench> is an adaptation of the similar
-script in the L<JSON::XS> distribution. The script L<F<benchmarks/pub-bench.pl>|https://github.com/benkasminbullock/JSON-Parse/e10440285845d6b0f29746bce84c6b546e557f6f/benchmarks/pub-bench.pl> runs the benchmarks and prints them
+script L<F<benchmarks/bench>|https://github.com/benkasminbullock/JSON-Parse/27b70e98176290ddd145cadfe8aa6ff43bb71703/benchmarks/bench> is an adaptation of the similar
+script in the L<JSON::XS> distribution. The script L<F<benchmarks/pub-bench.pl>|https://github.com/benkasminbullock/JSON-Parse/27b70e98176290ddd145cadfe8aa6ff43bb71703/benchmarks/pub-bench.pl> runs the benchmarks and prints them
out as POD.
The following benchmark tests used version 0.58_01 of JSON::Parse, version 4.03 of L</JSON::XS>, and version 4.25 of L</Cpanel::JSON::XS> on Perl
@@ -1434,6 +1467,11 @@ L<JSON::Repair> is an example module which demonstrates using
JSON::Parse to apply some kinds of heuristics to repair "relaxed JSON"
or otherwise broken JSON into compliant JSON.
+=item JSON::Server
+
+L<JSON::Server> is a module which offers a JSON-only, UTF-8 only
+server using C<JSON::Parse> and L</JSON::Create>.
+
=item JSON::Tokenize
L<JSON::Tokenize> is part of the JSON::Parse distribution, a tokenizer
@@ -1441,6 +1479,10 @@ which reduces a JSON string to tokens. This makes the JSON::Parse
tokenizer available to people who want to write their own JSON
parsers.
+=item JSON::Whitespace
+
+L<JSON::Whitespace> is for stripping whitespace from JSON.
+
=back
@@ -1488,7 +1530,7 @@ Perl structure wholesale into JSON.
=item L<JSON>
-[⭐⭐ Author: L<ISHIGAKI|https://metacpan.org/author/ISHIGAKI>; Date: C<2019-02-23>; Version: C<4.02>]
+[⭐⭐ Author: L<ISHIGAKI|https://metacpan.org/author/ISHIGAKI>; Date: C<2021-01-24>; Version: C<4.03>]
@@ -1513,7 +1555,7 @@ strings, trailing commas, etc.
=item L<JSON::PP>
-[⭐⭐ Author: L<ISHIGAKI|https://metacpan.org/author/ISHIGAKI>; Date: C<2020-07-08>; Version: C<4.05>]
+[⭐⭐ Author: L<ISHIGAKI|https://metacpan.org/author/ISHIGAKI>; Date: C<2021-01-23>; Version: C<4.06>]
@@ -1592,7 +1634,7 @@ requests have been ignored.
=item L<Mojo::JSON>
-[⭐⭐⭐ Author: L<SRI|https://metacpan.org/author/SRI>; Date: C<2020-12-30>; Version: C<8.70>]
+[⭐⭐⭐ Author: L<SRI|https://metacpan.org/author/SRI>; Date: C<2021-01-17>; Version: C<8.71>]
@@ -1910,7 +1952,7 @@ tied scalars.
=back
-=item Patch, path, pointer, and transform modules
+=item Patch, path, pointer, schema, and transform modules
=over
@@ -1983,6 +2025,17 @@ Transform JSON using JsonT
+
+=item L<JSON::Validator>
+
+
+[⭐⭐ Author: L<JHTHORSEN|https://metacpan.org/author/JHTHORSEN>; Date: C<2021-01-24>; Version: C<4.12>]
+
+
+
+"Validate data against a JSON schema" - you can decide what the JSON
+is supposed to contain.
+
=back
=item JSON extensions
@@ -2028,6 +2081,17 @@ These modules extend JSON with comments and other things.
=over
+=item L<Crypt::JWT>
+
+
+[⭐⭐ Author: L<MIK|https://metacpan.org/author/MIK>; Date: C<2021-01-10>; Version: C<0.031>]
+
+
+
+Module covers JSON Web Tokens, JSON Web Signature, and JSON Web
+Encryption.
+
+
=item L<JSON::API>
@@ -2140,8 +2204,8 @@ L<our bug report|https://github.com/pegex-parser/pegex-json-pm/issues/3>.
=item Other modules
-Modules which are parts of bigger releases have not been included here
-except by accident.
+Modules which are parts of bigger distributions have not been included
+here except by accident.
=over
@@ -2180,14 +2244,12 @@ the forked module L</Cpanel::JSON::XS>.
-=item L<Haineko::JSON>
-
+=item L<Jasonify>
-[⭐ Author: L<AKXLIX|https://metacpan.org/author/AKXLIX>; Date: C<2014-01-25>; Version: C<v0.2.16>]
+[Author: L<BOBK|https://metacpan.org/author/BOBK>; Date: C<2020-03-04>; Version: C<v0.20.064>]
-😕 We can't quite figure out the documentation here.
=item L<JS::JSON>
@@ -2278,8 +2340,6 @@ JavaScript object notation object notator.
-😕
-
=item L<JSON::Streaming::Reader>
@@ -2335,6 +2395,14 @@ the documentation, this module encodes numbers with quotes around
them, so C<< {this => 2} >> turns into C<{"this":"2"}>.
+=item L<JSON_minify>
+
+
+[Author: L<RCOSCALI|https://metacpan.org/author/RCOSCALI>; Date: C<2021-01-24>; Version: C<1.1>]
+
+
+
+
=item L<Text::JSON::Nibble>
@@ -2403,7 +2471,7 @@ supplied with the module in the F</t/> subdirectory of the
distribution.
More extensive testing code is in the git repository. This is not
-supplied in the CPAN distribution. A script, L<F<randomjson.pl>|https://github.com/benkasminbullock/JSON-Parse/e10440285845d6b0f29746bce84c6b546e557f6f/randomjson.pl>,
+supplied in the CPAN distribution. A script, L<F<randomjson.pl>|https://github.com/benkasminbullock/JSON-Parse/27b70e98176290ddd145cadfe8aa6ff43bb71703/randomjson.pl>,
generates a set number of bytes of random JSON and checks that the
module's bytewise validation of input is correct. It does this by
taking a valid fragment, then adding each possible byte from 0 to 255
@@ -2413,17 +2481,17 @@ it to the fragment and continuing the process until a complete valid
JSON input is formed. The module has undergone about a billion
repetitions of this test.
-This setup relies on a C file, L<F<json-random-test.c>|https://github.com/benkasminbullock/JSON-Parse/e10440285845d6b0f29746bce84c6b546e557f6f/json-random-test.c>, which
-isn't in the CPAN distribution, and it also requires L<F<Json3.xs>|https://github.com/benkasminbullock/JSON-Parse/e10440285845d6b0f29746bce84c6b546e557f6f/Json3.xs> to be edited to make the macro C<TESTRANDOM> true
+This setup relies on a C file, L<F<json-random-test.c>|https://github.com/benkasminbullock/JSON-Parse/27b70e98176290ddd145cadfe8aa6ff43bb71703/json-random-test.c>, which
+isn't in the CPAN distribution, and it also requires L<F<Json3.xs>|https://github.com/benkasminbullock/JSON-Parse/27b70e98176290ddd145cadfe8aa6ff43bb71703/Json3.xs> to be edited to make the macro C<TESTRANDOM> true
(uncomment line 7 of the file). The testing code uses C
setjmp/longjmp, so it's not guaranteed to work on all operating
systems and is commented out for CPAN releases.
-A pure C version called L<F<random-test.c>|https://github.com/benkasminbullock/JSON-Parse/e10440285845d6b0f29746bce84c6b546e557f6f/random-test.c> also exists. This applies
+A pure C version called L<F<random-test.c>|https://github.com/benkasminbullock/JSON-Parse/27b70e98176290ddd145cadfe8aa6ff43bb71703/random-test.c> also exists. This applies
exactly the same tests, and requires no Perl at all.
If you're interested in testing your own JSON parser, the outputs
-generated by L<F<randomjson.pl>|https://github.com/benkasminbullock/JSON-Parse/e10440285845d6b0f29746bce84c6b546e557f6f/randomjson.pl> are quite a good place to
+generated by L<F<randomjson.pl>|https://github.com/benkasminbullock/JSON-Parse/27b70e98176290ddd145cadfe8aa6ff43bb71703/randomjson.pl> are quite a good place to
start. The default is to produce UTF-8 output, which looks pretty
horrible since it tends to produce long strings of UTF-8
garbage. (This is because it chooses randomly from 256 bytes and the
@@ -2463,9 +2531,7 @@ Suite.
=over
-=item L<ActiveState PPM|http://code.activestate.com/ppm/JSON-Parse/>.
-
-=item L<CPAN testers|http://matrix.cpantesters.org/?dist=JSON-Parse+0.59>
+=item L<CPAN testers|http://matrix.cpantesters.org/?dist=JSON-Parse+0.60>
=item L<Travis CI|https://travis-ci.com/github/benkasminbullock/JSON-Parse>
diff --git a/lib/JSON/Tokenize.pm b/lib/JSON/Tokenize.pm
index 859a972..064af5f 100644
--- a/lib/JSON/Tokenize.pm
+++ b/lib/JSON/Tokenize.pm
@@ -4,10 +4,18 @@ use strict;
require Exporter;
our @ISA = qw(Exporter);
use JSON::Parse;
-our @EXPORT_OK = qw/tokenize_json tokenize_start tokenize_next tokenize_start tokenize_end tokenize_type tokenize_child tokenize_text/;
+our @EXPORT_OK = qw/
+ tokenize_child
+ tokenize_end
+ tokenize_json
+ tokenize_next
+ tokenize_start
+ tokenize_text
+ tokenize_type
+ /;
our %EXPORT_TAGS = ('all' => \@EXPORT_OK);
use Carp;
-our $VERSION = '0.59';
+our $VERSION = '0.60';
sub tokenize_text
{
diff --git a/lib/JSON/Tokenize.pod b/lib/JSON/Tokenize.pod
index 0551fbd..dedb3db 100644
--- a/lib/JSON/Tokenize.pod
+++ b/lib/JSON/Tokenize.pod
@@ -3,12 +3,13 @@
=head1 NAME
-JSON::Tokenize - tokenize a string containing JSON
+JSON::Tokenize - Tokenize JSON
=head1 SYNOPSIS
use JSON::Tokenize ':all';
+
my $input = '{"tuttie":["fruity", true, 100]}';
my $token = tokenize_json ($input);
print_tokens ($token, 0);
@@ -22,7 +23,7 @@ JSON::Tokenize - tokenize a string containing JSON
my $type = tokenize_type ($token);
print " " x $depth;
my $value = substr ($input, $start, $end - $start);
- print ">>$value<< has type $type\n";
+ print "'$value' has type '$type'.\n";
my $child = tokenize_child ($token);
if ($child) {
print_tokens ($child, $depth+1);
@@ -35,31 +36,32 @@ JSON::Tokenize - tokenize a string containing JSON
This outputs
- >>{"tuttie":["fruity", true, 100]}<< has type object
- >>"tuttie"<< has type string
- >>:<< has type colon
- >>["fruity", true, 100]<< has type array
- >>"fruity"<< has type string
- >>,<< has type comma
- >>true<< has type literal
- >>,<< has type comma
- >>100<< has type number
+ '{"tuttie":["fruity", true, 100]}' has type 'object'.
+ '"tuttie"' has type 'string'.
+ ':' has type 'colon'.
+ '["fruity", true, 100]' has type 'array'.
+ '"fruity"' has type 'string'.
+ ',' has type 'comma'.
+ 'true' has type 'literal'.
+ ',' has type 'comma'.
+ '100' has type 'number'.
=head1 VERSION
-This documents version 0.59 of JSON::Tokenize corresponding to
-L<git commit e10440285845d6b0f29746bce84c6b546e557f6f|https://github.com/benkasminbullock/JSON-Parse/commit/e10440285845d6b0f29746bce84c6b546e557f6f> released on Mon Jan 4 08:46:00 2021 +0900.
+This documents version 0.60 of JSON::Tokenize corresponding to
+L<git commit 27b70e98176290ddd145cadfe8aa6ff43bb71703|https://github.com/benkasminbullock/JSON-Parse/commit/27b70e98176290ddd145cadfe8aa6ff43bb71703> released on Tue Jan 26 08:51:47 2021 +0900.
=head1 DESCRIPTION
-This is a module for tokenizing a JSON string. It breaks the string
-into individual tokens without creating any Perl structures. Thus it
-can be used for tasks such as picking out or searching through parts
-of a large JSON structure without storing each part of the entire
-structure as individual Perl variables in memory.
+This is a module for tokenizing a JSON string. "Tokenizing" means
+breaking the string into individual tokens, without creating any Perl
+structures. It uses the same underlying code as
+L<JSON::Parse>. Tokenizing can be used for tasks such as picking out
+or searching through parts of a large JSON structure without storing
+each part of the entire structure in memory.
This module is an experimental part of L<JSON::Parse> and its
interface is likely to change. The tokenizing functions are currently
@@ -67,6 +69,19 @@ written in a very primitive way.
=head1 FUNCTIONS
+=head2 tokenize_child
+
+ my $child = tokenize_child ($child);
+
+Walk the tree of tokens.
+
+=head2 tokenize_end
+
+ my $end = tokenize_end ($token);
+
+Get the end of the token as a byte offset from the start of the
+string. Note this is a byte offset not a character offset.
+
=head2 tokenize_json
my $token = tokenize_json ($json);
@@ -77,12 +92,6 @@ written in a very primitive way.
Walk the tree of tokens.
-=head2 tokenize_child
-
- my $child = tokenize_child ($child);
-
-Walk the tree of tokens.
-
=head2 tokenize_start
my $start = tokenize_start ($token);
@@ -90,12 +99,14 @@ Walk the tree of tokens.
Get the start of the token as a byte offset from the start of the
string. Note this is a byte offset not a character offset.
-=head2 tokenize_end
+=head2 tokenize_text
- my $end = tokenize_end ($token);
+ my $text = tokenize_text ($json, $token);
-Get the end of the token as a byte offset from the start of the
-string. Note this is a byte offset not a character offset.
+Given a token C<$token> from this parsing and the JSON in C<$json>,
+return the text which corresponds to the token. This is a convenience
+function written in Perl which uses L</tokenize_start> and
+L</tokenize_end> and C<substr> to get the string from C<$json>.
=head2 tokenize_type
@@ -103,24 +114,15 @@ string. Note this is a byte offset not a character offset.
Get the type of the token as a string. The possible return values are
- "invalid",
+ "array",
"initial state",
- "string",
- "number",
+ "invalid",
"literal",
+ "number",
"object",
- "array",
+ "string",
"unicode escape"
-=head2 tokenize_text
-
- my $text = tokenize_text ($json, $token);
-
-Given a token C<$token> from this parsing and the JSON in C<$json>,
-return the text which corresponds to the token. This is a convenience
-function written in Perl which uses L</tokenize_start> and
-L</tokenize_end> and C<substr> to get the string from C<$json>.
-
=head1 AUTHOR
diff --git a/lib/JSON/Whitespace.pm b/lib/JSON/Whitespace.pm
new file mode 100644
index 0000000..64513d8
--- /dev/null
+++ b/lib/JSON/Whitespace.pm
@@ -0,0 +1,26 @@
+package JSON::Whitespace;
+use warnings;
+use strict;
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw/json_minify/;
+our %EXPORT_TAGS = (
+ all => \@EXPORT_OK,
+);
+
+use warnings;
+use strict;
+use Carp;
+our $VERSION = '0.60';
+
+use JSON::Tokenize 'tokenize_json';
+
+sub json_minify
+{
+ my ($json) = @_;
+ my $tokens = tokenize_json ($json);
+ my $nospace = strip_whitespace ($tokens, $json);
+ return $nospace;
+}
+
+1;
diff --git a/lib/JSON/Whitespace.pod b/lib/JSON/Whitespace.pod
new file mode 100644
index 0000000..86f77cc
--- /dev/null
+++ b/lib/JSON/Whitespace.pod
@@ -0,0 +1,83 @@
+
+=encoding UTF-8
+
+=head1 NAME
+
+JSON::Whitespace - Alter the insignificant whitespace of JSON
+
+=head1 SYNOPSIS
+
+ use JSON::Whitespace ':all';
+
+ my $in = <<EOF;
+ {
+ "animals":{
+ "kingkong":"🦍"
+ },
+ "baka":[
+ "ドジ"
+ ],
+ "fruit":{
+ "grape":"🍇"
+ },
+ "moons":{
+ "🌑":0
+ }
+ }
+ EOF
+ my $minify = json_minify ($in);
+ print $minify;
+
+
+This outputs
+
+ {"animals":{"kingkong":"🦍"},"baka":["ドジ"],"fruit":{"grape":"🍇"},"moons":{"🌑":0}}
+
+=head1 VERSION
+
+This documents version 0.60 of JSON::Whitespace corresponding to
+L<git commit 27b70e98176290ddd145cadfe8aa6ff43bb71703|https://github.com/benkasminbullock/JSON-Parse/commit/27b70e98176290ddd145cadfe8aa6ff43bb71703> released on Tue Jan 26 08:51:47 2021 +0900.
+
+
+
+=head1 DESCRIPTION
+
+This module offers functions to manipulate the "insignificant
+whitespace" part of a JSON string (the whitespace which is not inside
+strings). According to L<the JSON specification|JSON::Parse/SEE ALSO>
+"insignificant whitespace" consists of space (C<%x20>), horizontal tab
+(C<%x09>), line feed or new line (C<%x0A>) and carriage return
+(C<%x0D).
+
+=head1 FUNCTIONS
+
+=head2 json_minify
+
+ my $minified = json_minify ($json);
+
+Remove all whitespace, including trailing newlines, from C<$json>.
+
+=head1 SEE ALSO
+
+Documentation about JSON is in L<JSON::Parse>. JSON::Whitespace is
+based on L<JSON::Tokenize>, which breaks JSON into tokens without
+putting it into Perl structures.
+
+
+
+=head1 AUTHOR
+
+Ben Bullock, <bkb@cpan.org>
+
+=head1 COPYRIGHT & LICENCE
+
+This package and associated files are copyright (C)
+2016-2021
+Ben Bullock.
+
+You can use, copy, modify and redistribute this package and associated
+files under the Perl Artistic Licence or the GNU General Public
+Licence.
+
+
+
diff --git a/see-also-info.json b/see-also-info.json
deleted file mode 100644
index cfdacf9..0000000
--- a/see-also-info.json
+++ /dev/null
@@ -1,499 +0,0 @@
-[
- {
- "author":"RURBAN",
- "date":"2020-10-28T07:04:49",
- "fav":37,
- "module":"Cpanel::JSON::XS",
- "version":"4.25"
- },
- {
- "author":"NEILB",
- "date":"2020-11-18T09:21:24",
- "fav":3,
- "module":"File::JSON::Slurper",
- "version":"1.00"
- },
- {
- "author":"EBASSI",
- "date":"2015-04-19T19:16:21",
- "fav":1,
- "module":"Glib::JSON",
- "version":"0.002"
- },
- {
- "author":"ISHIGAKI",
- "date":"2019-02-23T02:26:27",
- "fav":92,
- "module":"JSON",
- "version":"4.02"
- },
- {
- "author":"DOWENS",
- "date":"2010-09-29T04:57:36",
- "fav":0,
- "module":"JSON::DWIW",
- "version":"0.47"
- },
- {
- "author":"ISHIGAKI",
- "date":"2020-07-08T19:51:42",
- "fav":15,
- "module":"JSON::PP",
- "version":"4.05"
- },
- {
- "author":"SRCHULO",
- "date":"2019-10-30T15:44:51",
- "fav":1,
- "module":"JSON::Slurper",
- "version":"0.12"
- },
- {
- "author":"TODDR",
- "date":"2020-10-26T20:20:42",
- "fav":17,
- "module":"JSON::Syck",
- "version":"1.34"
- },
- {
- "author":"DAVIDO",
- "date":"2017-11-12T16:01:34",
- "fav":13,
- "module":"JSON::Tiny",
- "version":"0.58"
- },
- {
- "author":"MLEHMANN",
- "date":"2020-10-27T18:06:42",
- "fav":108,
- "module":"JSON::XS",
- "version":"4.03"
- },
- {
- "author":"LBROCARD",
- "date":"2011-08-05T06:41:39",
- "fav":2,
- "module":"JSON::YAJL",
- "version":"0.10"
- },
- {
- "author":"SRI",
- "date":"2020-12-30T14:43:19",
- "fav":435,
- "module":"Mojo::JSON",
- "version":"8.70"
- },
- {
- "author":"ETHER",
- "date":"2015-06-10T04:38:55",
- "fav":5,
- "module":"JSON::Any",
- "version":"1.39"
- },
- {
- "author":"ETHER",
- "date":"2020-11-13T04:34:16",
- "fav":43,
- "module":"JSON::MaybeXS",
- "version":"1.004003"
- },
- {
- "author":"LBROCARD",
- "date":"2008-02-13T09:47:27",
- "fav":0,
- "module":"JSON::XS::VersionOneAndTwo",
- "version":"0.31"
- },
- {
- "author":"DBOOK",
- "date":"2019-08-07T17:02:05",
- "fav":8,
- "module":"Mojo::JSON::MaybeXS",
- "version":"1.002"
- },
- {
- "author":"AKIYM",
- "date":"2019-08-07T21:53:49",
- "fav":0,
- "module":"Test2::Tools::JSON",
- "version":"0.05"
- },
- {
- "author":"MOTEMEN",
- "date":"2018-04-24T11:24:46",
- "fav":5,
- "module":"Test::Deep::JSON",
- "version":"0.05"
- },
- {
- "author":"OVID",
- "date":"2009-08-09T09:20:24",
- "fav":4,
- "module":"Test::JSON",
- "version":"0.11"
- },
- {
- "author":"VOJ",
- "date":"2012-09-14T14:38:20",
- "fav":0,
- "module":"Test::JSON::Entails",
- "version":"0.2"
- },
- {
- "author":"BAYASHI",
- "date":"2016-04-28T01:29:13",
- "fav":0,
- "module":"Test::JSON::More",
- "version":"0.02"
- },
- {
- "author":"AEREAL",
- "date":"2015-10-26T10:54:03",
- "fav":0,
- "module":"JSON::TypeInference",
- "version":"v1.0.2"
- },
- {
- "author":"TYPESTER",
- "date":"2012-10-17T04:37:16",
- "fav":3,
- "module":"JSON::Types",
- "version":"0.05"
- },
- {
- "author":"PINE",
- "date":"2017-04-01T11:08:58",
- "fav":0,
- "module":"JSON::Types::Flexible",
- "version":"0.03"
- },
- {
- "author":"RJBS",
- "date":"2019-12-26T19:23:05",
- "fav":1,
- "module":"JSON::Typist",
- "version":"0.006"
- },
- {
- "author":"DOLMEN",
- "date":"2015-03-04T23:40:22",
- "fav":2,
- "module":"App::JSON::to",
- "version":"1.000"
- },
- {
- "author":"INGY",
- "date":"2016-07-08T17:14:57",
- "fav":14,
- "module":"boolean",
- "version":"0.46"
- },
- {
- "author":"RIZEN",
- "date":"2014-12-25T23:07:43",
- "fav":0,
- "module":"Config::JSON",
- "version":"1.5202"
- },
- {
- "author":"DOLMEN",
- "date":"2017-09-03T04:54:00",
- "fav":3,
- "module":"Devel::JSON",
- "version":"1.001"
- },
- {
- "author":"KILNA",
- "date":"2012-07-27T18:49:38",
- "fav":0,
- "module":"Inline::JSON",
- "version":"v1.0.4"
- },
- {
- "author":"KNI",
- "date":"2015-04-16T14:27:05",
- "fav":0,
- "module":"JSON::Builder",
- "version":"0.04"
- },
- {
- "author":"PERLANCAR",
- "date":"2020-06-09T10:44:00",
- "fav":3,
- "module":"JSON::Color",
- "version":"0.130"
- },
- {
- "author":"GETTY",
- "date":"2014-09-11T19:58:20",
- "fav":3,
- "module":"JSON_File",
- "version":"0.004"
- },
- {
- "author":"TOBYINK",
- "date":"2020-01-27T09:22:15",
- "fav":0,
- "module":"JSON::MultiValueOrdered",
- "version":"0.006"
- },
- {
- "author":"BRUMMETT",
- "date":"2015-02-04T20:19:07",
- "fav":0,
- "module":"JSON::String",
- "version":"v0.2.0"
- },
- {
- "author":"SOJIRO",
- "date":"2016-02-24T22:29:12",
- "fav":1,
- "module":"JSON::MergePatch",
- "version":"0.04"
- },
- {
- "author":"MIXAS",
- "date":"2018-10-25T21:09:47",
- "fav":0,
- "module":"JSON::Patch",
- "version":"0.04"
- },
- {
- "author":"POPEFELIX",
- "date":"2018-05-05T03:35:34",
- "fav":8,
- "module":"JSON::Path",
- "version":"0.420"
- },
- {
- "author":"ZIGOROU",
- "date":"2015-08-13T09:04:33",
- "fav":2,
- "module":"JSON::Pointer",
- "version":"0.07"
- },
- {
- "author":"TOBYINK",
- "date":"2014-09-28T07:42:10",
- "fav":1,
- "module":"JSON::T",
- "version":"0.104"
- },
- {
- "author":"ETJ",
- "date":"2020-01-01T15:21:38",
- "fav":1,
- "module":"JSON::Transform",
- "version":"0.03"
- },
- {
- "author":"PHAYLON",
- "date":"2014-12-10T02:45:53",
- "fav":1,
- "module":"JSON::Diffable",
- "version":"0.000002"
- },
- {
- "author":"MIKO",
- "date":"2016-04-30T18:37:10",
- "fav":0,
- "module":"JSON::Relaxed",
- "version":"0.05"
- },
- {
- "author":"INGY",
- "date":"2020-04-27T15:52:03",
- "fav":3,
- "module":"JSONY",
- "version":"v0.1.21"
- },
- {
- "author":"GFRANKS",
- "date":"2019-07-01T13:30:46",
- "fav":1,
- "module":"JSON::API",
- "version":"v1.1.1"
- },
- {
- "author":"SKINGTON",
- "date":"2018-05-11T18:29:32",
- "fav":1,
- "module":"LWP::JSON::Tiny",
- "version":"0.014"
- },
- {
- "author":"ANTIPASTA",
- "date":"2015-05-27T19:06:36",
- "fav":8,
- "module":"WWW::JSON",
- "version":"1.02"
- },
- {
- "author":"MAXMIND",
- "date":"2015-04-01T20:10:25",
- "fav":0,
- "module":"JSON::XS::Sugar",
- "version":"1.01"
- },
- {
- "author":"DROLSKY",
- "date":"2011-09-19T16:45:33",
- "fav":2,
- "module":"Silki::JSON",
- "version":"0.29"
- },
- {
- "author":"PERLANCAR",
- "date":"2014-08-27T16:03:43",
- "fav":0,
- "module":"JSON::Decode::Marpa",
- "version":"0.02"
- },
- {
- "author":"PERLANCAR",
- "date":"2018-03-25T12:23:33",
- "fav":0,
- "module":"JSON::Decode::Regexp",
- "version":"0.101"
- },
- {
- "author":"RSAVAGE",
- "date":"2019-06-18T06:20:04",
- "fav":0,
- "module":"MarpaX::Demo::JSONParser",
- "version":"1.08"
- },
- {
- "author":"INGY",
- "date":"2020-01-22T21:21:37",
- "fav":0,
- "module":"Pegex::JSON",
- "version":"0.31"
- },
- {
- "author":"KABLAMO",
- "date":"2016-08-05T14:51:20",
- "fav":0,
- "module":"App::JSON::Tools",
- "version":"0.01"
- },
- {
- "author":"MSTROUT",
- "date":"2011-02-02T00:09:45",
- "fav":6,
- "module":"App::JSONPretty",
- "version":"1"
- },
- {
- "author":"MOTEMEN",
- "date":"2013-12-18T01:24:28",
- "fav":1,
- "module":"ARGV::JSON",
- "version":"0.01"
- },
- {
- "author":"AKXLIX",
- "date":"2014-01-25T12:23:27",
- "fav":1,
- "module":"Haineko::JSON",
- "version":"v0.2.16"
- },
- {
- "author":"INGY",
- "date":"2008-08-30T03:41:24",
- "fav":0,
- "module":"JS::JSON",
- "version":"0.02"
- },
- {
- "author":"SGREEN",
- "date":"2017-07-07T05:50:07",
- "fav":0,
- "module":"JSON::Assert",
- "version":"0.08"
- },
- {
- "author":"TOBYINK",
- "date":"2019-10-27T22:23:49",
- "fav":0,
- "module":"JSON::Eval",
- "version":"0.002"
- },
- {
- "author":"MAJENSEN",
- "date":"2019-07-13T14:43:46",
- "fav":3,
- "module":"JSON::ize",
- "version":"0.202"
- },
- {
- "author":"HOEKIT",
- "date":"2016-04-23T03:25:28",
- "fav":0,
- "module":"JSON::JSend",
- "version":"0.02"
- },
- {
- "author":"LNATION",
- "date":"2020-10-25T12:34:39",
- "fav":1,
- "module":"JSON::Lines",
- "version":"0.03"
- },
- {
- "author":"ZOFFIX",
- "date":"2015-11-28T13:52:07",
- "fav":2,
- "module":"JSON::Meth",
- "version":"1.001007"
- },
- {
- "author":"EWILHELM",
- "date":"2013-06-26T22:29:17",
- "fav":0,
- "module":"JSON::ON",
- "version":"v0.0.3"
- },
- {
- "author":"MNUNBERG",
- "date":"2017-11-10T14:09:31",
- "fav":3,
- "module":"JSON::SL",
- "version":"v1.0.7"
- },
- {
- "author":"MART",
- "date":"2012-11-24T21:17:51",
- "fav":3,
- "module":"JSON::Streaming::Reader",
- "version":"0.06"
- },
- {
- "author":"MART",
- "date":"2012-11-24T21:14:59",
- "fav":0,
- "module":"JSON::Streaming::Writer",
- "version":"0.03"
- },
- {
- "author":"JKUTEJ",
- "date":"2015-09-03T16:00:14",
- "fav":0,
- "module":"JSON::Util",
- "version":"0.06"
- },
- {
- "author":"CINDY",
- "date":"2020-04-18T02:49:16",
- "fav":1,
- "module":"JSON::XS::ByteString",
- "version":"1.004"
- },
- {
- "author":"DAEMON",
- "date":"2017-05-02T05:16:57",
- "fav":0,
- "module":"Text::JSON::Nibble",
- "version":"1.01"
- }
-]
diff --git a/t/JPT.pm b/t/JPT.pm
new file mode 100644
index 0000000..24042f9
--- /dev/null
+++ b/t/JPT.pm
@@ -0,0 +1,33 @@
+package JPT;
+
+use warnings;
+use strict;
+use utf8;
+use Test::More;
+use JSON::Parse ':all';
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = (qw/daft_test/, @Test::More::EXPORT, @JSON::Parse::EXPORT_OK);
+
+# Set all the file handles to UTF-8
+
+my $builder = Test::More->builder;
+binmode $builder->output, ":encoding(utf8)";
+binmode $builder->failure_output, ":encoding(utf8)";
+binmode $builder->todo_output, ":encoding(utf8)";
+binmode STDOUT, ":encoding(utf8)";
+binmode STDERR, ":encoding(utf8)";
+
+sub import
+{
+ my ($class) = @_;
+
+ strict->import ();
+ utf8->import ();
+ warnings->import ();
+ Test::More->import ();
+ JSON::Parse->import (':all');
+ JPT->export_to_level (1);
+}
+
+1;
diff --git a/t/JSON-Parse.t b/t/JSON-Parse.t
index 6eb31f6..7a6fadf 100644
--- a/t/JSON-Parse.t
+++ b/t/JSON-Parse.t
@@ -1,16 +1,9 @@
-use warnings;
-use strict;
-use Test::More;
-use JSON::Parse qw/parse_json valid_json parse_json_safe/;
-use utf8;
-
-binmode STDOUT, ":utf8";
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
-
-#binmode STDOUT, ":utf8";
+# This is a basic test of parsing JSON. See also Json3.t.
+
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
+
my $jason = <<'EOF';
{"bog":"log","frog":[1,2,3],"guff":{"x":"y","z":"monkey","t":[0,1,2.3,4,59999]}}
EOF
@@ -39,8 +32,7 @@ ok (! ($zs->{medea}->{nice}), "Parse false literal.");
ok (valid_json ($argonauts), "Valid OK JSON");
-# Test that empty inputs result in an undefined return value, and no
-# error message.
+# Test that empty inputs result in an error message.
eval {
my $Q = parse_json ('');
@@ -55,11 +47,13 @@ eval {
ok ($@, "Empty string makes error");
ok ($@ =~ /empty input/i, "Empty input error for empty input");
eval {
-my $S = parse_json (' ');
+ my $S = parse_json (' ');
};
ok ($@, "Empty string makes error");
ok ($@ =~ /empty input/i, "Empty input error for empty input");
+# Test that errors are produced if we are missing the final brace.
+
my $n;
eval {
$n = '{"骪":"\u9aaa"';
@@ -82,6 +76,7 @@ ok ($@, "found error");
ok (! valid_json ($n), "! Not valid missing end }");
+# Test that errors are produced if we are missing the initial brace {.
my $bad1 = '"bad":"city"}';
$@ = undef;
@@ -89,16 +84,17 @@ eval {
parse_json ($bad1);
};
ok ($@, "found error in '$bad1'");
-#like ($@, qr/stray characters/, "Error message as expected");
my $notjson = 'this is not lexable';
$@ = undef;
eval {
parse_json ($notjson);
};
ok ($@, "Got error message");
-#like ($@, qr/stray characters/i, "unlexable message $@ OK");
ok (! valid_json ($notjson), "Not valid bad json");
+# This is the example from either the JSON RFC or from Douglas
+# Crockford's web page.
+
my $wi =<<EOF;
{
"firstName": "John",
diff --git a/t/Json3.t b/t/Json3.t
index 2865fb1..e646ea5 100644
--- a/t/Json3.t
+++ b/t/Json3.t
@@ -1,9 +1,8 @@
-# This is a test for module Json3.
+# These are basic tests for JSON::Parse.
-use warnings;
-use strict;
-use Test::More;
-use JSON::Parse 'parse_json';
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
# Empty array.
diff --git a/t/array.t b/t/array.t
index 12d8f16..6b59baa 100644
--- a/t/array.t
+++ b/t/array.t
@@ -1,7 +1,6 @@
-use warnings;
-use strict;
-use Test::More;
-use JSON::Parse ':all';
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
# This was a bug with uninitialized memory.
diff --git a/t/bugzilla-2049.t b/t/bugzilla-2049.t
index a8e36b5..ea5791c 100644
--- a/t/bugzilla-2049.t
+++ b/t/bugzilla-2049.t
@@ -1,7 +1,7 @@
-use warnings;
-use strict;
-use Test::More;
-use JSON::Parse 'read_json';
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
+
eval {
my $type = '';
my $tri2file = read_json ('$type-tri2file.txt');
diff --git a/t/collision.t b/t/collision.t
index ba237db..711a41d 100644
--- a/t/collision.t
+++ b/t/collision.t
@@ -1,16 +1,17 @@
-use warnings;
-use strict;
-use utf8;
+# This tests what happens when a JSON object has two keys with the
+# same string, as in {"a":1,"a":2}. These are called "collisions"
+# because the entries for the two bits of the JSON in the storing
+# object "collide".
+
use FindBin '$Bin';
-use Test::More;
+use lib "$Bin";
+use JPT;
+
+# We need to do some work with Unicode. This is a core module so it's
+# always available.
+
use Encode 'decode_utf8';
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
-binmode STDOUT, ":encoding(utf8)";
-binmode STDERR, ":encoding(utf8)";
-use JSON::Parse 'parse_json';
+
my $j = '{"a":1, "a":2}';
my $p = parse_json ($j);
cmp_ok ($p->{a}, '==', 2, "Test documented hash key collision behaviour");
@@ -28,6 +29,8 @@ eval {
ok ($@);
like ($@, qr/"hocus"/);
+# Test functioning with Unicode strings.
+
my $yodi = '{"ほかす":10,"ぽかす":20,"ほかす":30,"ふぉかす":40}';
eval {
$jp->run ($yodi);
diff --git a/t/json-tokenize.t b/t/json-tokenize.t
index 2de95b4..166f6e1 100644
--- a/t/json-tokenize.t
+++ b/t/json-tokenize.t
@@ -1,19 +1,10 @@
# Test for JSON::Tokenize
-use warnings;
-use strict;
-use utf8;
use FindBin '$Bin';
-use Test::More;
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
-binmode STDOUT, ":encoding(utf8)";
-binmode STDERR, ":encoding(utf8)";
-use JSON::Parse 'valid_json';
-use JSON::Tokenize;
+use lib "$Bin";
+use JPT;
use JSON::Tokenize ':all';
+
my $input = '{"tuttie":["fruity", true, 100]}';
ok (valid_json ($input));
my $token = tokenize_json ($input);
diff --git a/t/kolmorogov42-1.t b/t/kolmorogov42-1.t
index d1220e8..9452cd4 100644
--- a/t/kolmorogov42-1.t
+++ b/t/kolmorogov42-1.t
@@ -1,15 +1,13 @@
-use warnings;
-use strict;
-use utf8;
+# This tests behaviour against
+
+# https://github.com/benkasminbullock/JSON-Parse/issues/35
+
+# "Module crashes if field larger than just below 4 kB contains \n sequence"
+
use FindBin '$Bin';
-use Test::More;
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
-binmode STDOUT, ":encoding(utf8)";
-binmode STDERR, ":encoding(utf8)";
-use JSON::Parse 'parse_json';
+use lib "$Bin";
+use JPT;
+
my $input = <<'EOF';
{"date":1468338282,"text":"asasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdae\nrt432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasd555sdaert432fghyuiopasasddsasasasdasdasdasdasdasdasdasdassdfsdfsdfs"}
EOF
diff --git a/t/max-depth.t b/t/max-depth.t
index c2c837c..0e9ea84 100644
--- a/t/max-depth.t
+++ b/t/max-depth.t
@@ -1,17 +1,14 @@
-use warnings;
-use strict;
-use utf8;
+# This tests the "max depth" feature added so that the JSON Test Suite
+# silly test with 100,000 open { and [ doesn't cause an error.
+
use FindBin '$Bin';
-use Test::More;
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
-binmode STDOUT, ":encoding(utf8)";
-binmode STDERR, ":encoding(utf8)";
-use JSON::Parse;
+use lib "$Bin";
+use JPT;
my $jp = JSON::Parse->new ();
+
+# Test setting to "one" so that two [[ will cause an error.
+
$jp->set_max_depth (1);
my $ok = eval {
$jp->run ('[[[["should fail due to depth"]]]]');
@@ -20,6 +17,9 @@ my $ok = eval {
ok (! $ok, "fails to parse array when max depth is set to 1");
my $md = $jp->get_max_depth ();
cmp_ok ($md, '==', 1, "got back the max depth");
+
+# Test setting back to default using zero argument.
+
$jp->set_max_depth (0);
my $mdd = $jp->get_max_depth ();
cmp_ok ($mdd, '==', 10000, "got back the default max depth");
diff --git a/t/minify.t b/t/minify.t
new file mode 100644
index 0000000..d0eb85b
--- /dev/null
+++ b/t/minify.t
@@ -0,0 +1,37 @@
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
+use JSON::Whitespace ':all';
+
+my $in = <<EOF;
+{
+ "animals":{
+ "elephant":"🐘",
+ "goat":"🐐",
+ "kingkong":"🦍"
+ },
+ "baka":{
+ "あ":"ほ",
+ "ば":"か",
+ "ま":"ぬけ"
+ },
+ "fruit":{
+ "grape":"🍇",
+ "melon":"🍈",
+ "watermelon":"🍉"
+ },
+ "moons":{
+ "🌑":0,
+ "🌒":1,
+ "🌓":2,
+ "🌔":3,
+ "🌕":4,
+ "🌖":5,
+ "🌗":6,
+ "🌘":7
+ }
+ }
+EOF
+my $minify = json_minify ($in);
+is ($minify, '{"animals":{"elephant":"🐘","goat":"🐐","kingkong":"🦍"},"baka":{"あ":"ほ","ば":"か","ま":"ぬけ"},"fruit":{"grape":"🍇","melon":"🍈","watermelon":"🍉"},"moons":{"🌑":0,"🌒":1,"🌓":2,"🌔":3,"🌕":4,"🌖":5,"🌗":6,"🌘":7}}', "Removed whitespace from JSON");
+done_testing ();
diff --git a/t/numbers.t b/t/numbers.t
index 3ac4e1c..acf97c8 100644
--- a/t/numbers.t
+++ b/t/numbers.t
@@ -1,7 +1,6 @@
-use warnings;
-use strict;
-use JSON::Parse qw/json_to_perl parse_json/;
-use Test::More;
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
my $p;
@@ -9,10 +8,11 @@ my $p;
my $jeplus = '[1.9e+9]';
eval {
- $p = json_to_perl ($jeplus);
+ $p = parse_json ($jeplus);
};
-#note ($@);
ok (! $@, "Parsed $jeplus OK");
+cmp_ok ($p->[0], '==', 1.9e9, "Got a valid value");
+# Various kinds of numbers are valid as JSON.
my $j = <<EOF;
{
@@ -24,12 +24,14 @@ my $j = <<EOF;
"exponent":1.0E2
}
EOF
+
eval {
- $p = json_to_perl ($j);
+ $p = parse_json ($j);
};
-#note ($@);
ok (! $@, "Parsed OK");
+# Now make sure the numbers are the right ones.
+
ok (compare ($p->{integer}, 100), "Got 100 for integer");
ok (compare ($p->{decimal} , 1.5), "Got 1.5 for decimal");
ok (compare ($p->{exponent} , 100), "Got 100 for exponent");
@@ -37,17 +39,18 @@ ok (compare ($p->{"exponent-"} , 19/1000), "got 19/1000 for exponent-");
ok (compare ($p->{"exponent+"} , 1_900_000_000),
"got 1_900_000_000 for exponent+");
ok (compare ($p->{fraction} , 0.01), "got 0.01 for fraction");
-my $q = @{json_to_perl ('[0.12345]')}[0];
+my $q = @{parse_json ('[0.12345]')}[0];
ok (compare ($q, '0.12345'), "Got 0.12345");
# Illegal numbers
eval {
- json_to_perl ('[0...111]');
+ parse_json ('[0...111]');
};
ok ($@, "Don't accept 0...111");
+
eval {
- json_to_perl ('[0111]');
+ parse_json ('[0111]');
};
like ($@, qr/unexpected character/i, "Error for leading zero");
@@ -58,6 +61,8 @@ is ($out->[0], $long_number);
done_testing;
exit;
+# Compare floating point numbers.
+
sub compare
{
my ($x, $y) = @_;
@@ -65,6 +70,5 @@ sub compare
if (abs ($x - $y) < $error) {
return 1;
}
- print "$x and $y are not equal.\n";
return;
}
diff --git a/t/object.t b/t/object.t
index 62d6896..9036fb4 100644
--- a/t/object.t
+++ b/t/object.t
@@ -8,19 +8,9 @@
# ** Deletion of user-defined booleans
# * Detect hash collisions
-use warnings;
-use strict;
-use utf8;
use FindBin '$Bin';
-use Test::More;
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
-binmode STDOUT, ":encoding(utf8)";
-binmode STDERR, ":encoding(utf8)";
-
-use JSON::Parse;
+use lib "$Bin";
+use JPT;
# ____ _ _ _ _
# / ___|___ _ __ _ _ | (_) |_ ___ _ __ __ _| |___
diff --git a/t/perl-monks-1165399.t b/t/perl-monks-1165399.t
index 2bd3541..8f57393 100644
--- a/t/perl-monks-1165399.t
+++ b/t/perl-monks-1165399.t
@@ -1,19 +1,12 @@
-# http://perlmonks.org/?node_id=1165399
+# This is a test for the fix of the following bug:
# https://github.com/benkasminbullock/JSON-Parse/issues/34
-use warnings;
-use strict;
-use utf8;
+# There is also a discussion here:
+# http://perlmonks.org/?node_id=1165399
+
use FindBin '$Bin';
-use Test::More;
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
-binmode STDOUT, ":encoding(utf8)";
-binmode STDERR, ":encoding(utf8)";
-use Data::Dumper;
-use JSON::Parse;
+use lib "$Bin";
+use JPT;
my $j = JSON::Parse->new();
# no complain, no effect:
diff --git a/t/read-file.t b/t/read-file.t
index e3fb532..b58345e 100644
--- a/t/read-file.t
+++ b/t/read-file.t
@@ -1,9 +1,10 @@
-#!/home/ben/software/install/bin/perl
-use warnings;
-use strict;
-use Test::More;
+# This tests reading a file using the two different names of the
+# routine.
+
use FindBin '$Bin';
-use JSON::Parse qw!read_json json_file_to_perl!;
+use lib "$Bin";
+use JPT;
+
my $p = json_file_to_perl ("$Bin/test.json");
ok ($p->{distribution} eq 'Algorithm-NGram');
my $q = read_json ("$Bin/test.json");
diff --git a/t/rfc7159.t b/t/rfc7159.t
index 5b2542f..9d6f536 100644
--- a/t/rfc7159.t
+++ b/t/rfc7159.t
@@ -1,13 +1,11 @@
-use warnings;
-use strict;
-use Test::More;
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
-binmode STDOUT, ":encoding(utf8)";
-binmode STDERR, ":encoding(utf8)";
-use JSON::Parse qw/parse_json valid_json/;
+# This tests for the new behaviour of the JSON specification as of RFC
+# 7159 where a single item without braces {} or square brackets [] is
+# also valid as JSON.
+
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
+
my $stringonly = '"this"';
my $j;
eval {
diff --git a/t/string-bug-44.json b/t/string-bug-44.json
index 09dcef8..09dcef8 100755..100644
--- a/t/string-bug-44.json
+++ b/t/string-bug-44.json
diff --git a/t/string-bug-44.t b/t/string-bug-44.t
index 1c16853..1ae77eb 100755..100644
--- a/t/string-bug-44.t
+++ b/t/string-bug-44.t
@@ -1,10 +1,10 @@
-#!/home/ben/software/install/bin/perl
-use warnings;
-use strict;
-use utf8;
+# This was a bug in reading long strings.
+
+# https://github.com/benkasminbullock/JSON-Parse/issues/44
+
use FindBin '$Bin';
-use Test::More;
-use JSON::Parse 'read_json';
+use lib "$Bin";
+use JPT;
my $in = read_json ("$Bin/string-bug-44.json");
cmp_ok (length ($in->{x}), '==', 4080, "Length as expected");
done_testing ();
diff --git a/t/syntax.t b/t/syntax.t
index fc7bf9d..deee609 100644
--- a/t/syntax.t
+++ b/t/syntax.t
@@ -1,11 +1,10 @@
# This is a test for a false syntax error produced by this module on
# legitimate input.
-use warnings;
-use strict;
use FindBin '$Bin';
-use Test::More;
-use JSON::Parse 'read_json';
+use lib "$Bin";
+use JPT;
+
eval {
my $json = read_json ("$Bin/syntax-error-1.json");
};
diff --git a/t/test-empty-string.t b/t/test-empty-string.t
index e62ebe2..0b85c84 100644
--- a/t/test-empty-string.t
+++ b/t/test-empty-string.t
@@ -1,8 +1,7 @@
# This tests for an old bug where empty strings didn't work properly.
-use warnings;
-use strict;
-use JSON::Parse 'parse_json';
-use Test::More;
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
my $json = parse_json ('{"buggles":"","bibbles":""}');
is ($json->{buggles}, '');
is ($json->{bibbles}, '');
diff --git a/t/unicode.t b/t/unicode.t
index b7c96cc..8ad6c51 100644
--- a/t/unicode.t
+++ b/t/unicode.t
@@ -1,13 +1,6 @@
-use warnings;
-use strict;
-use Test::More;
-use JSON::Parse qw/json_to_perl valid_json parse_json/;
-use utf8;
-binmode STDOUT, ":utf8";
-my $builder = Test::More->builder;
-binmode $builder->output, ":utf8";
-binmode $builder->failure_output, ":utf8";
-binmode $builder->todo_output, ":utf8";
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
my $m = '{"骪":"\u9aaa"}';
ok (valid_json ($m), "Valid good JSON");
@@ -68,7 +61,7 @@ is (length ($p->[2]), 2, "length is two by magic");
ok (! valid_json ('["\uDE8C "]'), "invalid \uDE8C + space");
-# Test of the strangely-named "surrogate pairs".
+# Test of "surrogate pairs".
my $jc = JSON::Parse->new ();
my $wikipedia_1 = '"\ud801\udc37"';
diff --git a/t/utf8.t b/t/utf8.t
index 96b0d33..cbbe571 100644
--- a/t/utf8.t
+++ b/t/utf8.t
@@ -1,9 +1,10 @@
-use warnings;
-use strict;
-use Test::More;
-use JSON::Parse ':all';
+# Test UTF-8 processing.
-# Test valid JSON.
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
+
+# Test for valid and invalid JSON with Perl's flag switched off.
no utf8;
@@ -16,6 +17,7 @@ eval {
};
like ($@, qr/Unexpected character 0x80 parsing string/);
+# Test with the flag switched back on.
use utf8;
diff --git a/t/valid-json.t b/t/valid-json.t
index dbd48ab..f07fef5 100644
--- a/t/valid-json.t
+++ b/t/valid-json.t
@@ -2,10 +2,9 @@
# can fail, and also check that correct, yet weird or stupid inputs
# are not marked as invalid.
-use warnings;
-use strict;
-use Test::More;
-use JSON::Parse qw/valid_json validate_json/;
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
# https://github.com/benkasminbullock/JSON-Parse/issues/2
diff --git a/t/whitespace.t b/t/whitespace.t
index 4ef7a12..fdea086 100644
--- a/t/whitespace.t
+++ b/t/whitespace.t
@@ -1,7 +1,6 @@
-use warnings;
-use strict;
-use Test::More tests => 2;
-use JSON::Parse qw/valid_json json_to_perl/;
+use FindBin '$Bin';
+use lib "$Bin";
+use JPT;
my $json = <<EOF;
{
"timed_out" : false,
@@ -13,3 +12,4 @@ eval {
json_to_perl ($json);
};
ok (! $@, "No errors parsing JSON");
+done_testing ();