Today I'm officially augmenting my JSON2.ASP class with a toXML method which takes a Javascript object with JSON notation and returns it's XML version. My algorithm is a very fast implementation of the prof. Stefan Gössner bijective transformation between JSON and XML exposed in this article.

Example

This javascript:

var nagaozen = {
    full_name:"Fabio Zendhi Nagao",
    nickname: "nagaozen",
    gender: "male",
    age: 27,
    title: "Founder & CTO - Evolved",
    education: {
        "@active": true,
        technical: {
            location: "Federal Technique School of Sao Paulo",
            degree: "Technical data processing",
            final_work: "E-commerce framework"
        },
        undergraduate: {
            location: "University of Sao Paulo",
            degree: "BSc. Applied and Computational Mathematician",
            thesis: "Mathematical Modeling of Collective Intelligence"
        },
        graduate: {
            location: "University of Sao Paulo",
            degree: "MSc. Computing Science",
            thesis: "unknown"
        }
    },
    likes: ["Manoela", "Family (dogs included)", "Internet", "Programming", "Design", "Philosophy"],
    dislikes: [],
    a_few_aliens_i_know: {},
    contact: "nagaozen[at]evolved.com.br"
};
 

is converted into this XML:

<?xml version="1.0"?>
<human>
    <full_name>Fabio Zendhi Nagao</full_name>
    <nickname>nagaozen</nickname>
    <gender>male</gender>
    <age>27</age>
    <title>Founder &amp; CTO - Evolved</title>
    <education active="true">
        <technical>
            <location>Federal Technique School of Sao Paulo</location>
            <degree>Technical data processing</degree>
            <final_work>E-commerce framework</final_work>
        </technical>
        <undergraduate>
            <location>University of Sao Paulo</location>
            <degree>BSc. Applied and Computational Mathematician</degree>
            <thesis>Mathematical Modeling of Collective Intelligence</thesis>
        </undergraduate>
        <graduate>
            <location>University of Sao Paulo</location>
            <degree>MSc. Computing Science</degree>
            <thesis>unknown</thesis>
        </graduate>
    </education>
    <likes>Manoela</likes>
    <likes>Family (dogs included)</likes>
    <likes>Internet</likes>
    <likes>Programming</likes>
    <likes>Design</likes>
    <likes>Philosophy</likes>
    <dislikes/>
    <a_few_aliens_i_know/>
    <contact>nagaozen[at]evolved.com.br</contact>
</human>
 

Download

  • Get JSON2.ASP from inside the ASP Xtreme Evolution repository.