JSON::YAJL::Parser works great for me when parsing files as a single
chunk or small files line by line. It segfaults for big files.
I managed to reproduce the problem on my system with relatively small
file ( it is attached ). Test script is attached also. When run as
'./json_parse.pl test.json' it prints:
--------
Attempt to free unreferenced scalar: SV 0x21c5220, Perl interpreter:
0x21c4010 at ./json_parse.pl line 26, <$fh> line 3.
Attempt to free unreferenced scalar: SV 0x21c5220, Perl interpreter:
0x21c4010 at ./json_parse.pl line 26, <$fh> line 4.
Attempt to free unreferenced scalar: SV 0x21c5220, Perl interpreter:
0x21c4010 at ./json_parse.pl line 26, <$fh> line 5.
map_open
string: key1
string: 1
string: key2
number: 1
string: mapping
string: ... <== removed long string here
map_close
Segmentation fault
--------
perl v5.8.8 built for x86_64-linux-thread-multi
(repeated with simple "Segmentation fault" on perl v5.12.4)
JSON::YAJL v0.10
I will provide more info if you ask me and explain how can I get it.
Subject: | test.json |
{
"key1": "1",
"key2": 1,
"mapping": "{\"users\":{\"looks\":{\"properties\":{\"title\":{\"type\":\"string\"},\"items\":{\"type\":\"string\"},\"rawdate\":{\"type\":\"long\"},\"best\":{\"type\":\"string\"},\"UserID\":{\"type\":\"string\"},\"photo\":{\"type\":\"string\"}}},\"friends\":{\"properties\":{\"friendID\":{\"type\":\"string\"},\"UserID\":{\"type\":\"string\"}}},\"wish\":{\"properties\":{\"id\":{\"type\":\"string\"},\"clone\":{\"dynamic\":\"true\",\"properties\":{\"shop\":{\"type\":\"string\"},\"offerCategoryId\":{\"type\":\"string\"},\"param\":{\"dynamic\":\"true\",\"properties\":{\"content\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"}}},\"currencyId\":{\"type\":\"string\"},\"variations\":{\"dynamic\":\"true\",\"properties\":{\"variation\":{\"dynamic\":\"true\",\"properties\":{\"vendorCode\":{\"type\":\"string\"},\"order_article\":{\"type\":\"string\"},\"color\":{\"type\":\"string\"},\"color_image\":{\"type\":\"string\"},\"order_size\":{\"type\":\"string\"},\"order_price\":{\"type\":\"string\"},\"url\":{\"type\":\"string\"},\"size\":{\"type\":\"string\"}}}}},\"kid\":{\"type\":\"long\"},\"child\":{\"type\":\"long\"},\"id\":{\"type\":\"long\"},\"is_new\":{\"type\":\"string\"},\"catalog_image\":{\"type\":\"string\"},\"description\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"length\":{\"type\":\"string\"},\"offerCategoryName\":{\"type\":\"string\"},\"baby\":{\"type\":\"long\"},\"necklineForm\":{\"type\":\"string\"},\"hood\":{\"type\":\"string\"},\"popularity\":{\"type\":\"long\"},\"sizeList\":{\"type\":\"string\"},\"oldPrice\":{\"type\":\"long\"},\"article_group_number\":{\"type\":\"string\"},\"vendor\":{\"type\":\"string\"},\"elegance\":{\"type\":\"string\"},\"colorList\":{\"type\":\"string\"},\"male\":{\"type\":\"long\"},\"currencyRate\":{\"type\":\"long\"},\"available\":{\"type\":\"long\"},\"adult\":{\"type\":\"string\"},\"sysSize\":{\"type\":\"string\"},\"picture\":{\"type\":\"string\"},\"shopURL\":{\"type\":\"string\"},\"price\":{\"type\":\"long\"},\"season\":{\"type\":\"string\"},\"female\":{\"type\":\"string\"},\"typePrefix\":{\"type\":\"string\"},\"categories\":{\"dynamic\":\"true\",\"properties\":{\"category\":{\"dynamic\":\"true\",\"properties\":{\"id\":{\"type\":\"string\"},\"content\":{\"type\":\"string\"},\"parentId\":{\"type\":\"long\"}}}}},\"sleeveLength\":{\"type\":\"string\"}}},\"rawdate\":{\"type\":\"long\"},\"UserID\":{\"type\":\"string\"}}},\"fav\":{\"properties\":{\"id\":{\"type\":\"string\"},\"clone\":{\"dynamic\":\"true\",\"properties\":{\"shop\":{\"type\":\"string\"},\"offerCategoryId\":{\"type\":\"string\"},\"param\":{\"dynamic\":\"true\",\"properties\":{\"content\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"}}},\"currencyId\":{\"type\":\"string\"},\"variations\":{\"dynamic\":\"true\",\"properties\":{\"variation\":{\"dynamic\":\"true\",\"properties\":{\"vendorCode\":{\"type\":\"string\"},\"order_article\":{\"type\":\"string\"},\"color\":{\"type\":\"string\"},\"color_image\":{\"type\":\"string\"},\"order_size\":{\"type\":\"string\"},\"order_price\":{\"type\":\"string\"},\"url\":{\"type\":\"string\"},\"size\":{\"type\":\"string\"}}}}},\"kid\":{\"type\":\"long\"},\"child\":{\"type\":\"long\"},\"id\":{\"type\":\"long\"},\"is_new\":{\"type\":\"string\"},\"catalog_image\":{\"type\":\"string\"},\"description\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"length\":{\"type\":\"string\"},\"offerCategoryName\":{\"type\":\"string\"},\"baby\":{\"type\":\"long\"},\"necklineForm\":{\"type\":\"string\"},\"hood\":{\"type\":\"string\"},\"popularity\":{\"type\":\"long\"},\"sizeList\":{\"type\":\"string\"},\"oldPrice\":{\"type\":\"long\"},\"article_group_number\":{\"type\":\"string\"},\"vendor\":{\"type\":\"string\"},\"elegance\":{\"type\":\"string\"},\"colorList\":{\"type\":\"string\"},\"male\":{\"type\":\"long\"},\"currencyRate\":{\"type\":\"long\"},\"available\":{\"type\":\"long\"},\"adult\":{\"type\":\"string\"},\"sysSize\":{\"type\":\"string\"},\"picture\":{\"type\":\"string\"},\"shopURL\":{\"type\":\"string\"},\"price\":{\"type\":\"long\"},\"season\":{\"type\":\"string\"},\"female\":{\"type\":\"string\"},\"typePrefix\":{\"type\":\"string\"},\"categories\":{\"dynamic\":\"true\",\"properties\":{\"category\":{\"dynamic\":\"true\",\"properties\":{\"id\":{\"type\":\"string\"},\"content\":{\"type\":\"string\"},\"parentId\":{\"type\":\"long\"}}}}},\"sleeveLength\":{\"type\":\"string\"}}},\"rawdate\":{\"type\":\"long\"},\"UserID\":{\"type\":\"string\"}}},\"frequests\":{\"properties\":{\"friendID\":{\"type\":\"string\"},\"UserID\":{\"type\":\"string\"}}},\"user\":{\"properties\":{\"tmp\":{\"type\":\"boolean\"},\"rawdate\":{\"type\":\"long\"},\"UserName\":{\"type\":\"string\"}}},\"trial\":{\"properties\":{\"id\":{\"type\":\"string\"},\"color\":{\"type\":\"string\"},\"rawdate\":{\"type\":\"long\"},\"UserID\":{\"type\":\"string\"},\"size\":{\"type\":\"string\"}}},\"comments\":{\"properties\":{\"text\":{\"type\":\"string\"},\"attach_id\":{\"type\":\"string\"},\"rawdate\":{\"type\":\"long\"},\"UserID\":{\"type\":\"string\"},\"type\":{\"type\":\"string\"},\"date\":{\"type\":\"string\"},\"ourUserID\":{\"type\":\"string\"}}}},\"vitrina\":{\"offer\":{\"properties\":{\"shop\":{\"type\":\"string\"},\"_source\":{\"dynamic\":\"true\",\"properties\":{\"shop\":{\"type\":\"string\"},\"offerCategoryId\":{\"type\":\"string\"},\"currencyId\":{\"type\":\"string\"},\"variations\":{\"dynamic\":\"true\",\"properties\":{\"variation\":{\"dynamic\":\"true\",\"properties\":{\"vendorCode\":{\"type\":\"string\"},\"order_article\":{\"type\":\"string\"},\"color\":{\"type\":\"string\"},\"color_image\":{\"type\":\"string\"},\"order_size\":{\"type\":\"string\"},\"order_price\":{\"type\":\"string\"},\"url\":{\"type\":\"string\"},\"size\":{\"type\":\"string\"}}}}},\"kid\":{\"type\":\"long\"},\"child\":{\"type\":\"long\"},\"id\":{\"type\":\"long\"},\"is_new\":{\"type\":\"string\"},\"description\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"length\":{\"type\":\"string\"},\"offerCategoryName\":{\"type\":\"string\"},\"baby\":{\"type\":\"long\"},\"necklineForm\":{\"type\":\"string\"},\"hood\":{\"type\":\"string\"},\"popularity\":{\"type\":\"long\"},\"sizeList\":{\"type\":\"string\"},\"local_delivery_cost\":{\"dynamic\":\"true\",\"type\":\"object\"},\"oldPrice\":{\"type\":\"long\"},\"article_group_number\":{\"type\":\"string\"},\"vendor\":{\"type\":\"string\"},\"elegance\":{\"type\":\"string\"},\"colorList\":{\"type\":\"string\"},\"male\":{\"type\":\"long\"},\"currencyRate\":{\"type\":\"long\"},\"available\":{\"type\":\"long\"},\"adult\":{\"type\":\"string\"},\"sysSize\":{\"type\":\"string\"},\"picture\":{\"type\":\"string\"},\"shopURL\":{\"type\":\"string\"},\"price\":{\"type\":\"long\"},\"season\":{\"type\":\"string\"},\"female\":{\"type\":\"string\"},\"typePrefix\":{\"type\":\"string\"},\"categories\":{\"dynamic\":\"true\",\"properties\":{\"category\":{\"dynamic\":\"true\",\"properties\":{\"id\":{\"type\":\"string\"},\"content\":{\"type\":\"string\"},\"parentId\":{\"type\":\"long\"}}}}},\"delivery\":{\"dynamic\":\"true\",\"type\":\"object\"},\"sleeveLength\":{\"type\":\"string\"}}},\"param\":{\"dynamic\":\"true\",\"properties\":{\"content\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"}}},\"offerCategoryId\":{\"type\":\"string\"},\"currencyId\":{\"type\":\"string\"},\"variations\":{\"dynamic\":\"true\",\"properties\":{\"variation\":{\"dynamic\":\"true\",\"properties\":{\"vendorCode\":{\"type\":\"string\"},\"order_article\":{\"type\":\"string\"},\"color\":{\"type\":\"string\"},\"color_image\":{\"type\":\"string\"},\"order_size\":{\"type\":\"string\"},\"order_price\":{\"type\":\"string\"},\"url\":{\"type\":\"string\"},\"size\":{\"type\":\"string\"}}}}},\"kid\":{\"type\":\"long\"},\"child\":{\"type\":\"long\"},\"id\":{\"type\":\"long\"},\"is_new\":{\"type\":\"string\"},\"catalog_image\":{\"type\":\"string\"},\"description\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"offerCategoryName\":{\"type\":\"string\"},\"length\":{\"type\":\"string\"},\"baby\":{\"type\":\"long\"},\"necklineForm\":{\"type\":\"string\"},\"hood\":{\"type\":\"string\"},\"popularity\":{\"type\":\"long\"},\"sizeList\":{\"type\":\"string\"},\"oldPrice\":{\"type\":\"long\"},\"local_delivery_cost\":{\"dynamic\":\"true\",\"type\":\"object\"},\"article_group_number\":{\"type\":\"string\"},\"vendor\":{\"type\":\"string\"},\"elegance\":{\"type\":\"string\"},\"colorList\":{\"type\":\"string\"},\"male\":{\"type\":\"long\"},\"currencyRate\":{\"type\":\"long\"},\"_index\":{\"type\":\"string\"},\"available\":{\"type\":\"long\"},\"adult\":{\"type\":\"string\"},\"sysSize\":{\"type\":\"string\"},\"picture\":{\"type\":\"string\"},\"shopURL\":{\"type\":\"string\"},\"price\":{\"type\":\"long\"},\"season\":{\"type\":\"string\"},\"female\":{\"type\":\"string\"},\"typePrefix\":{\"type\":\"string\"},\"categories\":{\"dynamic\":\"true\",\"properties\":{\"category\":{\"dynamic\":\"true\",\"properties\":{\"id\":{\"type\":\"string\"},\"content\":{\"type\":\"string\"},\"parentId\":{\"type\":\"long\"}}}}},\"delivery\":{\"dynamic\":\"true\",\"type\":\"object\"},\"sleeveLength\":{\"type\":\"string\"}}}}}"
}
Subject: | json_parse.pl |
#!/usr/bin/perl
use JSON::YAJL;
my $filename = shift || die 'Please pass a JSON filename to reformat';
my $text;
my $parser = JSON::YAJL::Parser->new(
0, 0,
[ sub { $text .= "null\n" },
sub { $text .= "bool: @_\n" },
undef,
undef,
sub { $text .= "number: @_\n" },
sub { $text .= "string: @_\n" },
sub { $text .= "map_open\n" },
sub { $text .= "string: @_\n" },
sub { $text .= "map_close\n" },
sub { $text .= "array_open\n" },
sub { $text .= "array_close\n" },
]
);
open my $fh, $filename or die "Cannot open data file: $!";
while ( <$fh> ){
$parser->parse( $_ );
}
$parser->parse_complete();
print $text . "\n";