JSON::Tokenize(3)
π NAME π
okay so welcome to the JSON::Tokenize(3) page, straight out of the User Contributed Perl Documentation aisle, bestie π«Ά
JSON::Tokenize β tokenize JSON. that's the name, that's the vibe, no cap β¨
β¨ SYNOPSIS β¨
bestie, here's the whole demo, and yes, we're printing tokens recursively like it's a little family tree π³
use JSON::Tokenize ':all';
my $input = '{"tuttie":["fruity", true, 100]}';
my $token = tokenize_json ($input);
print_tokens ($token, 0);
sub print_tokens
{
my ($token, $depth) = @_;
while ($token) {
my $start = tokenize_start ($token);
my $end = tokenize_end ($token);
my $type = tokenize_type ($token);
print " " x $depth;
my $value = substr ($input, $start, $end - $start);
print "'$value' has type '$type'.\n";
my $child = tokenize_child ($token);
if ($child) {
print_tokens ($child, $depth+1);
}
my $next = tokenize_next ($token);
$token = $next;
}
}
and then you get this exact output, iconic:
'{"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'.
π¦ VERSION π¦
this page documents version 0.62 of JSON::Tokenize, and it corresponds to git commit d04630086f6c92fea720cba4568faa0cbbdde5a6 β the URL is https://github.com/benkasminbullock/JSON-Parse/commit/d04630086f6c92fea720cba4568faa0cbbdde5a6 β and it was released on Sat Jul 16 08:23:13 2022 +0900 β
πΈ DESCRIPTION πΈ
okay so JSON::Tokenize is a module for tokenizing a JSON string. and βtokenizingβ means breaking the string into individual tokens, without creating any Perl structures π
It uses the same underlying code as 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 π§ β¨
warning bestie π¨ this module is an experimental part of JSON::Parse, and its interface is likely to change. the tokenizing functions are currently written in a very primitive way. so like, don't build your whole personality on the API staying put, okay? π
π FUNCTIONS π
π§ tokenize_child
my $child = tokenize_child ($child);
walk the tree of tokens, bestie π³ this is how you get the child token.
π tokenize_end
my $end = tokenize_end ($token);
grab the end of the token as a byte offset from the start of the string. and important: this is a byte offset, not a character offset π
π tokenize_json
my $token = tokenize_json ($json);
this is the signature, and the original page literally doesn't add extra prose here β it's just the call, no cap π«Ά
π¦ tokenize_next
my $next = tokenize_next ($token);
walk the tree of tokens β that's the note, and it's giving traversal energy π
π§ tokenize_start
my $start = tokenize_start ($token);
get the start of the token as a byte offset from the start of the string. again, byte offset, not character offset β don't forget it, bestie π
πΈ tokenize_text
my $text = tokenize_text ($json, $token);
given a token $token from this parsing and the JSON in $json, return the text which corresponds to the token. it's a convenience function written in Perl, and it uses tokenize_start, tokenize_end, and substr to get the string from $json β¨
π tokenize_type
my $type = tokenize_type ($token);
get the type of the token as a string. the possible return values are literally these:
"array""initial state""invalid""literal""number""object""string""unicode escape"
so yeah, those are the type strings you might see π
π AUTHOR π
Ben Bullock, <bkb@cpan.org> β that's the author, bestie π
π COPYRIGHT & LICENCE π
this package and associated files are copyright (C) 2016-2022 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 π«Ά
and that's the page! shoutout to perl v5.42.0, the 2022-07-16 date, and JSON::Tokenize(3) β this bestie is signing off, mwah π
π¦ where this page comes from
- opensuse-leap 16.0: perl-JSON-Parse 0.62-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-JSON-Parse 0.62-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-JSON-Parse 0.62-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-JSON-Parse 0.62-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms