Converting XMLDocument to JSON or data wrangling with XML

hi @ciscorucinski,

Recently someone had a similar issue here trying to parse a RSS feed, which is essentially a XML document. Then @visnup made this notebook with a helper to convert a XML to JSON, which is the best format for your data on Observable.

You can import


import { xmlToJSON } from '@visnup/xml-to-json'

load the XML text

xmlString = fetch( `https://ciscorucinski-cors.herokuapp.com/http://openapi.data.go.kr/openapi/service/rest/Covid19/getCovid19SidoInfStateJson?serviceKey=${Secret('KEY_DATA.GO.KR')}&pageNo=1&numOfRows=100&startCreateDt=20200920&endCreateDt=20200920`
).then(res => res.text())

parse the data

data = xmlToJSON(xmlString)
items = data.response.body.items.item

here is live notebook in case you need https://observablehq.com/d/40d489d25fcf288b

1 Like