Created: 2008-06-13 17:58
Updated: 2016-05-08 09:40
License: mit


hypomodern prototype jxparser

This is version 0.1 of a xml-to-json-to-xml parser that I am working on. I wanted something lightweight and tight, and with a MIT or similar license. I couldn't find anything that fit all of those bills, so here's the DIY version. This software is designed for use with prototype, but could easily be ported to be framework-neutral.

This is version 0.1! It takes XML and converts it to JSON. It ignores your attribute specifications (because I'm not sure how to handle them well and the projects I'm on don't need me to handle attributes, so...) and doesn't do a very good job typecasting. But hey, if what you need is some XML converted to JSON, it works. The file itself is littered with commentary, but here's the basics:

What it does

The output from parsing something that looks like this:

  <updated-at type="datetime">2008-05-12T15:22:19-04:00</updated-at>

is something like this:

var json = {
  manufacturer: {
    name: "Acme",
    updated_at: 2008-05-12T15:22:19-04:00

json.manufacturer.name // => "Acme"

More examples:

<locations type=\"array\">
    <id type=\"integer\">2</id>
    <name>330 32nd Street</name>
    <updated-at type=\"datetime\">2008-04-15T11:51:52-04:00</updated-at>
    <id type=\"integer\">3</id>
    <name>332 32nd Street</name>
    <updated-at type=\"datetime\">2008-04-15T11:51:52-04:00</updated-at>

var json = {
  locations: {
    location: [
      { id: 2, name: "330 32nd Street", level_name: "Area", updated_at:...},
      { id: 3, name: "332 32nd Street", level_name: "Area", updated_at:...}

json.locations.location[1].name // => "332 32nd Street"


var json = { 
  framulator_cost: "$32.58"

json.framulator_cost // => "$32.58"

etc. etc.

Have fun!

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more