WWW::Metaweb::JSONLikePerl - Access a JSON string like a Perl structure
use strict; use WWW::Metaweb::JSONLikePerl qw(:standard); my json = qq({ "cover_appearances": [ { "part_of_series": "Runaways", "type": "/comic_books/comic_book_issue", "name": "Runaways Vol 1 #1" }, { "part_of_series": "Runaways", "type": "/comic_books/comic_book_issue", "name": "Runaways Vol. 2 #1" }, { "part_of_series": "Mystic Arcana", "type": "/comic_books/comic_book_issue", "name": "Mystic Arcana Book IV: Fire" } ], "name": "Nico Minoru", "created_by": ["Brian K. Vaughan"], "/type/object/creator": "/user/metaweb", "type": "/comic_books/comic_book_character", "id": "/topic/en/nico_minoru" }); my $id = $jsonlp_fetch('->{id}', $json); my new_json; $new_json = jsonlp_replace('->{cover_appearances}->[2]->{name}', $json, 'Mystic Arcana IV: Sister Grimm'); $new_json = jsonlp_insert('->{created_by}', $json, 'Adrian Alphona'); my $second_json = qq({ "query":{ "country":null, "name":99507, "type":["/location/postal_code"] } }); $new_json = jsonlp_quote('->{query}->{name}', $second_json, '"'); $new_json = jsonlp_unquote('->{query}->{type}', $second_json);
WWW::Metaweb::JSONLikePerl allows manipulation of a JSON string, referencing items like a perl structure, but without actually converting the string.
Returns the value of the item in $json_string pointed to by $structure_path.
$json_string
$structure_path
If include_quotes is true then whatever may be quoting the value being fetched will also be included, this may be '{ }' for a hash, '[ ]' for an array, '" "' for a string or make no difference if it's a number or bare word.
include_quotes
{ }
[ ]
" "
Replaces the specified JSON node with $replacement_value.
$replacement_value
Inserts $text_to_insert into the specified JSON node.
$text_to_insert
Quotes the specified node as specified by $quote_characters.
$quote_characters
If $quote_characters has a length of 1 (such as '"') the specified node will be surrounded by that character (eg. "994002"). If it has a length of 2 (such as '{}') the first character will go before the specified node, the second character will go acter the specified node (eg. {994002}). Any other number o characters and undef will be returned.
"
"994002"
{}
{994002}
undef
Removes quotes from the specified node.
None of either as of yet.
Mainly the Barcelona weather for keeping me up late enough to come up with this crazy idea.
JSON, WWW::Metaweb
Hayden Stainsby <hds@cpan.org>
Copyright (C) 2007 by Hayden Stainsby
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install WWW::Metaweb, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Metaweb
CPAN shell
perl -MCPAN -e shell install WWW::Metaweb
For more information on module installation, please visit the detailed CPAN module installation guide.