Git Product home page Git Product logo

mojolicious-plugin-jsontoxml's Introduction

NAME

Mojolicious::Plugin::JsonToXml - JSON to XML Mojolicious Plugin

SYNOPSIS

# Mojolicious
$self->plugin('json_to_xml');

# Mojolicious::Lite
plugin 'json_to_xml';

# or
plugin 'json_to_xml', { status => 200 }; # JSON to XML only 200 status code

# or
plugin 'json_to_xml', {
        exclude => [ qr{/no\.xml}, '/no2.xml' ] # Exclude urls
};

Simple:

get '/test.json' => sub { shift->render_json({ response => 'ok' }) };

# /test.json : {"response": "ok"}
# /test.xml  :
<?xml version="1.0" encoding="UTF-8"?>
<response>ok</response>

List:

get '/list.json' => sub { shift->render_json([1, 2, 3]) };

# /list.json : [1,2,3]
# /list.xml  :
<?xml version="1.0" encoding="UTF-8"?>
<list><item>1</item><item>2</item><item>3</item></list>

Tags:

get '/tags.json' => sub { shift->render_json({
        tests => [
                { id => 1, title => 'JSON & XML', __node => 'test' },
                { id => 2, title => 'JSON > XML', },
        ]
}) };

# /tags.json : {"tests":[{"id":1},{"id":2}]}
# /tags.xml  :
<?xml version="1.0" encoding="UTF-8"?>
<tests>
        <test><id>1</id><title>JSON &amp; XML</title></test>
        <test><id>2</id><title>JSON &gt; XML</title></test>
</tests>

DESCRIPTION

Mojolicous::Plugin::JsonToXml is a plugin to easily use XML format if exists JSON format. Automatiс render JSON to XML data

METHODS

Mojolicious::Plugin::JsonToXml inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

$plugin->register;

Register plugin hooks in Mojolicious application.

json2xml

my $xml = $plugin->json2xml( $json );

Simple render json to xml.

If $json is missing or empty, xml contains root tag <empty />.

Each element of array is <item> ... </item>.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicious.org.

AUTHOR

Anatoly Sharifulin <[email protected]>

BUGS

Please report any bugs or feature requests to bug-mojolicious-plugin-jsontoxml at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.htMail?Queue=Mojolicious-Plugin-JsonToXml. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.

COPYRIGHT & LICENSE

Copyright (C) 2010 by Anatoly Sharifulin.

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

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 60:

Non-ASCII character seen before =encoding in 'Automatiс'. Assuming UTF-8

mojolicious-plugin-jsontoxml's People

Contributors

sharifulin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.