WWW::Metaweb::JSONLikePerl - Access a JSON string like a Perl structure


WWW-Metaweb documentation  | view source Contained in the WWW-Metaweb distribution.

Index


NAME

Top

WWW::Metaweb::JSONLikePerl - Access a JSON string like a Perl structure

SYNOPSIS

Top

  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);

ABSTRACT

Top

WWW::Metaweb::JSONLikePerl allows manipulation of a JSON string, referencing items like a perl structure, but without actually converting the string.

EXPORTABLE FUNCTIONS

Top

$value = jsonlp_fetch($structure_path, $json_string, [include_quotes])

Returns the value of the item in $json_string pointed to by $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.

$new_json = jsonlp_replace($structure_path, $json_string, $replacement_value)

Replaces the specified JSON node with $replacement_value.

$new_json = jsonlp_insert($structure_path, $json_string, $text_to_insert)

Inserts $text_to_insert into the specified JSON node.

$new_json = jsonlp_quote($structure_path, $json_string, $quote_characters)

Quotes the specified node as specified by $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.

$new_json = jsonlp_unquote($structure_path, $json_string)

Removes quotes from the specified node.

BUGS AND TODO

Top

None of either as of yet.

ACCKNOWLEDGEMENTS

Top

Mainly the Barcelona weather for keeping me up late enough to come up with this crazy idea.

SEE ALSO

Top

JSON, WWW::Metaweb

AUTHORS

Top

Hayden Stainsby <hds@cpan.org>

COPYRIGHT AND LICENSE

Top


WWW-Metaweb documentation  | view source Contained in the WWW-Metaweb distribution.