GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Google::Data::JSON(3) User Contributed Perl Documentation Google::Data::JSON(3)

Google::Data::JSON - General XML-JSON converter based on Google Data APIs

    use Google::Data::JSON;

    ## Convert an XML document into a JSON and a Perl HASH.
    $gdata = Google::Data::JSON->new(xml => $xml);
    $json  = $gdata->as_json;
    $hash  = $gdata->as_hash;

    ## Convert a JSON into an XML document and an Atom object.
    $gdata = Google::Data::JSON->new(json => $json);
    $xml   = $gdata->as_xml;
    $atom  = $gdata->as_atom;

Google::Data::JSON provides several methods to convert an XML feed into a JSON feed, and vice versa. The JSON format is defined in Google Data APIs, http://code.google.com/apis/gdata/json.html .

This module is not restricted to Atom Feed. Any XML documents can be converted into JSON-format, and vice versa.

The following rules are described in Google Data APIs:

- The feed is represented as a JSON object; each nested element or attribute is represented as a name/value property of the object.

- Attributes are converted to String properties.

- Child elements are converted to Object properties.

- Elements that may appear more than once are converted to Array properties.

- Text values of tags are converted to $t properties.

- If an element has a namespace alias, the alias and element are concatenated using "$". For example, ns:element becomes ns$element.

- XML version and encoding attributes are converted to attribute version and encoding of the root element, respectively.

Creates a new parser object from $stream of $type , and returns the new Google::Data::JSON object. On failure, return "undef";

$type must be one of the followings:

xml
$stream must be a string containing XML.
json
$stream must be a string containing JSON.
atom
$stream must be an XML::Atom object, such as XML::Atom::Feed, XML::Atom::Entry, XML::Atom::Service, and XML::Atom::Categories.
hash
$stream must be a Perl hash referece, strictly saying, that is a reference to a data structure combined with HASH and ARRAY.
file
$stream must be a filename of XML or JSON.

Shortcut for Google::Data::JSON->new(...).

Converts into a string of XML.

Converts into a string of JSON.

Converts into an XML::Atom object.

Converts into a Perl HASH.

DEPRECATED

Returns an error message.

DEPRECATED

DEPRECATED

DEPRECATED

None by default.

The following example shows XML and JSON versions of the same document:

    <?xml version="1.0" encoding="utf-8"?>
    <feed xmlns="http://www.w3.org/2005/Atom"
          xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
      <title>Test Feed</title>
      <id>tag:example.com,2007:1</id>
      <updated>2007-01-01T00:00:00Z</updated>
      <link rel="self" href="http://example.com/feed.atom"/>
      <openSearch:startIndex>1</openSearch:startIndex>
      <entry>
        <title>Test Entry 1</title>
        <id>tag:example.com,2007:2</id>
        <updated>2007-02-01T00:00:00Z</updated>
        <published>2007-02-01T00:00:00Z</published>
        <link rel="alternate" href="http://example.com/1"/>
        <link rel="edit" href="http://example.com/edit/1"/>
        <author>
          <name>Foo</name>
          <email>foo@example.com</email>
        </author>
        <content type="xhtml">
          <div xmlns="http://www.w3.org/1999/xhtml">
            <span>Test 1</span>
          </div>
        </content>
      </entry>
      <entry>
        <title>Test Entry 2</title>
        <id>tag:example.com,2007:3</id>
        <updated>2007-03-01T00:00:00Z</updated>
        <published>2007-03-01T00:00:00Z</published>
        <link rel="alternate" href="http://example.com/2"/>
        <link rel="edit" href="http://example.com/edit/2"/>
        <author>
          <name>Bar</name>
          <email>bar@example.com</email>
        </author>
        <content type="xhtml">
          <div xmlns="http://www.w3.org/1999/xhtml">
            <span>Test 2</span>
          </div>
        </content>
      </entry>
    </feed>

    {
      "feed" : {
        "xmlns" : "http://www.w3.org/2005/Atom",
        "xmlns$openSearch" : "http://a9.com/-/spec/opensearchrss/1.0/",
        "title" : {
          "$t" : "Test Feed"
        },
        "id" : {
          "$t" : "tag:example.com,2007:1"
        },
        "updated" : {
          "$t" : "2007-01-01T00:00:00Z"
        },
        "link" : {
          "rel" : "self",
          "href" : "http://example.com/feed.atom"
        },
        "openSearch$startIndex" : {
          "$t" : "1"
        },
        "entry" : [
          {
            "published" : {
              "$t" : "2007-02-01T00:00:00Z"
            },
            "link" : [
              {
                "rel" : "alternate",
                "href" : "http://example.com/1"
              },
              {
                "rel" : "edit",
                "href" : "http://example.com/edit/1"
              }
            ],
            "content" : {
              "div" : {
                "xmlns" : "http://www.w3.org/1999/xhtml",
                "span" : {
                  "$t" : "Test 1"
                }
              },
              "type" : "xhtml"
            },
            "title" : {
              "$t" : "Test Entry 1"
            },
            "id" : {
              "$t" : "tag:example.com,2007:2"
            },
            "updated" : {
              "$t" : "2007-02-01T00:00:00Z"
            },
            "author" : {
              "email" : {
                "$t" : "foo@example.com"
              },
              "name" : {
                "$t" : "Foo"
              }
            }
          },
          {
            "published" : {
              "$t" : "2007-03-01T00:00:00Z"
            },
            "link" : [
              {
                "rel" : "alternate",
                "href" : "http://example.com/2"
              },
              {
                "rel" : "edit",
                "href" : "http://example.com/edit/2"
              }
            ],
            "content" : {
              "div" : {
                "xmlns" : "http://www.w3.org/1999/xhtml",
                "span" : {
                  "$t" : "Test 2"
                }
              },
              "type" : "xhtml"
            },
            "title" : {
              "$t" : "Test Entry 2"
            },
            "id" : {
              "$t" : "tag:example.com,2007:3"
            },
            "updated" : {
              "$t" : "2007-03-01T00:00:00Z"
            },
            "author" : {
              "email" : {
                "$t" : "bar@example.com"
              },
              "name" : {
                "$t" : "Bar"
              }
            }
          }
        ]
      }
    }

XML::Atom

Takeru INOUE "<takeru.inoue _ gmail.com>"

Copyright (c) 2007, Takeru INOUE "<takeru.inoue _ gmail.com>". All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

2022-04-13 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.