{"id":13426362,"url":"https://github.com/hrbrmstr/blackmagic","last_synced_at":"2025-10-29T01:30:44.849Z","repository":{"id":141238040,"uuid":"133787629","full_name":"hrbrmstr/blackmagic","owner":"hrbrmstr","description":"🎩 Automagically Convert XML to JSON an JSON to XML","archived":false,"fork":false,"pushed_at":"2018-05-18T02:37:53.000Z","size":157,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-01T00:53:59.304Z","etag":null,"topics":["json-to-xml","json-to-xml-converter","jsontoxml","r","r-cyber","rstats","xml-js","xml-to-json","xmltojson"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hrbrmstr.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-05-17T09:04:47.000Z","updated_at":"2021-04-16T06:55:03.000Z","dependencies_parsed_at":"2024-02-03T08:53:36.673Z","dependency_job_id":"e4f118fa-4901-4185-87fd-bdd128f24909","html_url":"https://github.com/hrbrmstr/blackmagic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fblackmagic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fblackmagic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fblackmagic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fblackmagic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hrbrmstr","download_url":"https://codeload.github.com/hrbrmstr/blackmagic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219858513,"owners_count":16556043,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-to-xml","json-to-xml-converter","jsontoxml","r","r-cyber","rstats","xml-js","xml-to-json","xmltojson"],"created_at":"2024-07-31T00:01:32.750Z","updated_at":"2025-10-29T01:30:44.476Z","avatar_url":"https://github.com/hrbrmstr.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"---\noutput: rmarkdown::github_document\neditor_options: \n  chunk_output_type: console\n---\n\n# blackmagic\n\nAutomagically Convert 'XML' to 'JSON'/'JSON' to 'XML'\n\n## Description\n\nGiven a character string of 'XML', an 'xml2' or 'XML' package document, or a 'URL' to retrieve XML content from, convert said 'XML' to 'JSON' using the 'xml-js' 'npm' library \u003chttps://www.npmjs.com/package/xml-js\u003e by Yousuf Almarzooqi. Also handles the reverse (e.g. 'JSON' to 'XML').\n    \n## NOTE\n\nPlease reconsider your apparent desire to use this package.\n\nAutomagic conversion of XML to JSON (or vice-versa) is _rarely_ a good idea and a path fraught with peril. There are _so many_ options to tweak to ensure you get what you think you want but likely truly want something else entirely, such as a more minimal extract of the original XML file.\n\nSeriously consider parsing the XML/JSON then using `purrr` idioms to extract the data you need into a proper `list` and _then_ call `jsonlite::toJSON()` or `xml2::as_xml_document()` on said `list`.\n\n## What's Inside The Tin\n\nThe following functions are implemented:\n\n- `xml_to_json`:\tConvert XML to JSON\n- `json_to_xml`:\tConvert JSON to XML\n\n## Installation\n\n```{r eval=FALSE}\ndevtools::install_github(\"hrbrmstr/blackmagic\")\n```\n\n```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE}\noptions(width=120)\n```\n\n## Usage\n\n```{r message=FALSE, warning=FALSE, error=FALSE}\nlibrary(blackmagic)\n\n# current verison\npackageVersion(\"blackmagic\")\n\n```\n\n### Sample (defaults)\n\n```{r}\n\nxml \u003c- '\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cnote importance=\"high\" logged=\"true\"\u003e\n    \u003ctitle\u003eHappy\u003c/title\u003e\n    \u003ctodo\u003eWork\u003c/todo\u003e\n    \u003ctodo\u003ePlay\u003c/todo\u003e\n\u003c/note\u003e'\n\ncat(xml_to_json(xml))\n```\n\n### Sample (`xml2`)\n\n```{r}\ncat(xml_to_json(xml2::read_xml(xml)))\n```\n\n### Sample (`XML`)\n\n```{r}\ncat(xml_to_json(XML::xmlParse(xml)))\n```\n\n### Sample (URL + saner tweaks)\n\n```{r}\ncat(xml_to_json(\"https://httpbin.org/xml\", spaces = 2, compact = FALSE, ignoreDeclaration = TRUE))\n```\n\n### Sample (some saner tweaks)\n\n```{r}\n'\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cbookstore\u003e\n  \u003cbook category=\"cooking\"\u003e\n    \u003ctitle lang=\"en\"\u003eEveryday Italian\u003c/title\u003e\n    \u003cauthor\u003eGiada De Laurentiis\u003c/author\u003e\n    \u003cyear\u003e2005\u003c/year\u003e\n    \u003cprice\u003e30.00\u003c/price\u003e\n  \u003c/book\u003e\n  \u003cbook category=\"children\"\u003e\n    \u003ctitle lang=\"en\"\u003eHarry Potter\u003c/title\u003e\n    \u003cauthor\u003eJ K. Rowling\u003c/author\u003e\n    \u003cyear\u003e2005\u003c/year\u003e\n    \u003cprice\u003e29.99\u003c/price\u003e\n  \u003c/book\u003e\n  \u003cbook category=\"web\"\u003e\n    \u003ctitle lang=\"en\"\u003eLearning XML\u003c/title\u003e\n    \u003cauthor\u003eErik T. Ray\u003c/author\u003e\n    \u003cyear\u003e2003\u003c/year\u003e\n    \u003cprice\u003e39.95\u003c/price\u003e\n  \u003c/book\u003e\n\u003c/bookstore\u003e' -\u003e books\n\ncat(xml_to_json(books, spaces = 2, compact = TRUE, ignoreDeclaration = TRUE))\n```\n\n### The other way 'round\n\n```{r}\ncat(json_to_xml(jsonlite::toJSON(head(mtcars, 2)), spaces=2))\n```\n\n### With a URL source\n\n```{r}\ncat(json_to_xml(\"https://httpbin.org/uuid\", spaces=2))\n```\n\n## Code of Conduct\n\nPlease note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fblackmagic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrbrmstr%2Fblackmagic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fblackmagic/lists"}