Methods to convert a XML string into a JSON string, and to covert a JSON string into an XML string.
R
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
R
inst/java
man
.Rbuildignore
.gitignore
DESCRIPTION
JSON2XML.Rproj
NAMESPACE
README.md

README.md

JSON2XML

USAGE

Using JSON2XML is straightforward. There are two functions for conversion: json2XML and xml2JSON.

xml2JSON

require(JSON2XML)
fileURL <-  "http://api.sportsdatallc.org/nfl-t1/2013/REG/1/statistics.xml?api_key=4dhyq3f3rfkp2cbm4yqbcuag"
xData <- readLines(fileURL)
jData <- xml2JSON(paste(xData, collapse='')) # convert to JSON
out <- RJSONIO::fromJSON(jData)
do.call(rbind.data.frame, out$games$game[[1]]$team[[1]][[c('defense', 'player')]])

json2XML

require(JSON2XML)
jsonString <- RJSONIO::toJSON(list(a=1, r = list(b = 2:3, c= 'd')), collapse = '')
xData <- json2XML(jsonString)
XML::xmlParse(json2XML(jsonString))

Getting started

To install JSON2XML you will need the devtools package. If necessary (install.packages("devtools")) and run:

devtools::install_github("johndharrison/JSON2XML")