{"id":13671550,"url":"https://github.com/buglabs/node-xml2json","last_synced_at":"2025-04-27T18:31:22.098Z","repository":{"id":1562773,"uuid":"1979533","full_name":"buglabs/node-xml2json","owner":"buglabs","description":"Converts XML to JSON using node-expat","archived":true,"fork":false,"pushed_at":"2020-10-22T10:20:26.000Z","size":258,"stargazers_count":811,"open_issues_count":55,"forks_count":211,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-18T18:31:50.842Z","etag":null,"topics":[],"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/buglabs.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2011-06-30T18:22:24.000Z","updated_at":"2025-02-21T09:15:54.000Z","dependencies_parsed_at":"2022-08-06T10:16:39.851Z","dependency_job_id":null,"html_url":"https://github.com/buglabs/node-xml2json","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buglabs%2Fnode-xml2json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buglabs%2Fnode-xml2json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buglabs%2Fnode-xml2json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buglabs%2Fnode-xml2json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buglabs","download_url":"https://codeload.github.com/buglabs/node-xml2json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251187158,"owners_count":21549596,"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":[],"created_at":"2024-08-02T09:01:12.695Z","updated_at":"2025-04-27T18:31:21.704Z","avatar_url":"https://github.com/buglabs.png","language":"JavaScript","readme":"# Simple XML2JSON Parser\n[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/buglabs/node-xml2json?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Build Status](https://travis-ci.org/buglabs/node-xml2json.svg?branch=master)](https://travis-ci.org/buglabs/node-xml2json)\n\nIt does not parse the following elements:\n\n* CDATA sections (*)\n* Processing instructions\n* XML declarations\n* Entity declarations\n* Comments\n\nThis module uses node-expat which will require extra steps if you want to get it installed on Windows. Please\nrefer to its [documentation](https://github.com/astro/node-expat/blob/master/README.md#windows).\n\n## Installation\n```\n$ npm install xml2json\n```\n\n## Usage\n```javascript\nvar parser = require('xml2json');\n\nvar xml = \"\u003cfoo attr=\\\"value\\\"\u003ebar\u003c/foo\u003e\";\nconsole.log(\"input -\u003e %s\", xml)\n\n// xml to json\nvar json = parser.toJson(xml);\nconsole.log(\"to json -\u003e %s\", json);\n\n// json to xml\nvar xml = parser.toXml(json);\nconsole.log(\"back to xml -\u003e %s\", xml)\n```\n\n## API\n\n```javascript\nparser.toJson(xml, options);\n```\n```javascript\nparser.toXml(json);\n```\n\n### Options object for `toJson`\n\nDefault values:\n```javascript\nvar options = {\n    object: false,\n    reversible: false,\n    coerce: false,\n    sanitize: true,\n    trim: true,\n    arrayNotation: false\n    alternateTextNode: false\n};\n```\n\n* **object:** Returns a Javascript object instead of a JSON string\n* **reversible:** Makes the JSON reversible to XML (*)\n* **coerce:** Makes type coercion. i.e.: numbers and booleans present in attributes and element values are converted from string to its correspondent data types. Coerce can be optionally defined as an object with specific methods of coercion based on attribute name or tag name, with fallback to default coercion.\n* **trim:** Removes leading and trailing whitespaces as well as line terminators in element values.\n* **arrayNotation:** XML child nodes are always treated as arrays NB: you can specify a selective array of nodes for this to apply to instead of the whole document. \n* **sanitize:** Sanitizes the following characters present in element values:\n\n```javascript\nvar chars =  {\n    '\u003c': '\u0026lt;',\n    '\u003e': '\u0026gt;',\n    '(': '\u0026#40;',\n    ')': '\u0026#41;',\n    '#': '\u0026#35;',\n    '\u0026': '\u0026amp;',\n    '\"': '\u0026quot;',\n    \"'\": '\u0026apos;'\n};\n```\n* **alternateTextNode:** Changes the default textNode property from $t to _t when option is set to true. Alternatively a string can be specified which will override $t to what ever the string is.\n\n\n### Options object for `toXml`\n\nDefault values:\n```javascript\nvar options = {\n    sanitize: false,\n    ignoreNull: false\n};\n```\n\n* `sanitize: false` is the default option to behave like previous versions\n* **ignoreNull:** Ignores all null values\n\n\n(*) xml2json tranforms CDATA content to JSON, but it doesn't generate a reversible structure.\n\n## License\n(The MIT License)\n\nCopyright (c) 2016 xml2json AUTHORS \n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to\ndeal in the Software without restriction, including without limitation the\nrights to use, copy, modify, merge, publish, distribute, sublicense, and/or\nsell copies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\nIN THE SOFTWARE.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuglabs%2Fnode-xml2json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuglabs%2Fnode-xml2json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuglabs%2Fnode-xml2json/lists"}