{"name":"simple-xml-to-json","version":"1.2.6","keywords":["XML","xml","JSON","json","js","xml2json","xml2js","convertor","conversion","parsing","parser","AST","ast","simple","fast","lightweight","small"],"author":{"name":"Nir Moav","email":"getnirm@gmail.com"},"license":"MIT","_id":"simple-xml-to-json@1.2.6","maintainers":[{"name":"nirmoav","email":"getnirm@gmail.com"}],"contributors":[{"url":"https://nirgit.github.io/","name":"Nir Moav","email":"getnirm@gmail.com"}],"homepage":"https://github.com/nirgit/simple-xml-to-json","bugs":{"url":"https://github.com/nirgit/simple-xml-to-json/issues"},"dist":{"shasum":"033658f690ebdd7db4d7cf7e24e475c4f7073482","tarball":"http://registry-npm.ywwl.com/simple-xml-to-json/download/simple-xml-to-json-1.2.6.tgz","fileCount":8,"integrity":"sha512-TypO01vko49ZeoU/Rv1TeDzUvlapN9hvTnrNHLnBtwaTTYCU6sI7iOPd5O96tb4xQA2HooosdeY3p0dRCmHViw==","signatures":[{"sig":"MEUCICwQbt6VYmIIzCfD2PyVQ0BMU0jOL0/oWpqIf6hYKWgcAiEAoaaGiBhqk6Gif8zsgzCP3nhfdliaB0IJsL1R8y3fczQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":47163,"size":11944,"noattachment":false,"key":"/simple-xml-to-json/-/simple-xml-to-json-1.2.6.tgz"},"main":"lib/simpleXmlToJson.min.js","module":"lib/simpleXmlToJson.min.mjs","engines":{"node":">=20.12.2"},"exports":{".":{"types":"./typings/simple-xml-to-json.d.ts","import":"./lib/simpleXmlToJson.min.mjs","default":"./lib/simpleXmlToJson.min.js","require":"./lib/simpleXmlToJson.min.js"}},"gitHead":"88c101fa37eae4bbe6beae403240ff491ac07998","scripts":{"lint":"eslint ./src ./test","test":"NODE_OPTIONS=--experimental-vm-modules jest","build":"npm run clean && rollup -c --inline","clean":"rm -rf ./lib/ && mkdir lib ","example":"node example/example.js","prettify":"prettier --write ./**/*.js","exampleESM":"node example/example.mjs","validate-lib-health":"npm run prettify && npm run lint && npm test","make-new-release-lib":"npm run validate-lib-health && sh ./scripts/make-new-release.sh"},"typings":"typings/simple-xml-to-json.d.ts","_npmUser":{"name":"nirmoav","email":"getnirm@gmail.com"},"repository":{"url":"git+https://github.com/nirgit/simple-xml-to-json.git","type":"git"},"_npmVersion":"11.6.2","description":"Convert XML to JSON - Fast & Simple","directories":{},"_nodeVersion":"24.11.1","_hasShrinkwrap":false,"devDependencies":{"jest":"30.3.0","acorn":"8.16.0","eslint":"10.2.0","rollup":"4.60.1","globals":"17.4.0","prettier":"3.2.5","acorn-walk":"8.3.5","magic-string":"^0.30.10","eslint-plugin-jest":"29.15.1","@rollup/plugin-terser":"1.0.0","@rollup/plugin-replace":"6.0.3","eslint-config-prettier":"10.1.8","@rollup/plugin-commonjs":"29.0.2"},"_npmOperationalInternal":{"tmp":"tmp/simple-xml-to-json_1.2.6_1775551576711_0.35871099926350714","host":"s3://npm-registry-packages-npm-production"},"readme":"# A simple XML to JSON converter\n\n[![npm version](https://img.shields.io/npm/v/simple-xml-to-json.svg?style=flat-square)](https://www.npmjs.com/package/simple-xml-to-json)\n[![Test CI](https://github.com/nirgit/simple-xml-to-json/actions/workflows/node.js.yml/badge.svg)](https://github.com/nirgit/simple-xml-to-json/actions/workflows/node.js.yml)\n[![codecov](https://codecov.io/gh/nirgit/simple-xml-to-json/branch/master/graph/badge.svg?token=XW7CWWM4RV)](https://codecov.io/gh/nirgit/simple-xml-to-json)\n\n## Install\nSimply install using NPM in your project directory\n> npm install simple-xml-to-json\n\n\n## Usage and API\n### 1. convertXML(xmlToConvert [,customConverter])\n   * `xmlToConvert` \\<string\\>\n   * `customConverter` \\<function\\>\n   * Returns: \\<JSON\\> by default or other if `customConverter` is used\n   \n### 2. createAST(xmlToConvert)\n   * `xmlToConvert` \\<string\\>\n   * Returns: An AST representation of the XML \\<JSON\\>\n\n**CommonJS (Node.js):**\n```javascript\nconst { convertXML, createAST } = require(\"simple-xml-to-json\")\n\nconst myJson = convertXML(myXMLString)\nconst myYaml = convertXML(myXMLString, yamlConverter)\nconst myAst = createAST(myXMLString)\n```\n\n**ESM (modern frontend apps, Node.js with `\"type\": \"module\"`, bundlers):**\n```javascript\nimport { convertXML, createAST } from \"simple-xml-to-json\"\n\nconst myJson = convertXML(myXMLString)\nconst myYaml = convertXML(myXMLString, yamlConverter)\nconst myAst = createAST(myXMLString)\n```\n\n---\n### ![TS](https://raw.githubusercontent.com/nirgit/assets/master/simple-xml-to-json/ts_icon_32.png) Typescript compatible\n---\n\n## Notes and how to use code\n1. The easiest thing to start is to run `node example/example.js` (CJS) or `node example/example.mjs` (ESM) in your terminal and see what happens.\n2. There's the `xmlToJson.js` file for convenience. Just pass in the XML as a String.\n3. MIT licensed allowing code customization\n4. Profit\n\n## How this works in a nutshell\n1. The library converts the XML to an AST\n2. There is a JSON converter that takes the AST and spits out a JSON\n3. You can write your own converters if you need XML-to-ANY-OTHER-FORMAT\n\n## Benchmark\n\n_Take these results with a grain of salt._\\\nAccording to a __simple__ benchmark test I performed in __April 2024__ with a random XML. _YMMV_.\n![Benchmark Chart](https://github.com/nirgit/assets/blob/master/simple-xml-to-json/simple-xml-to-json-benchmark-2.png?raw=true)\n\n* The chart results __may be__ outdated. [Run the test yourself](https://runkit.com/nirgit/6620cf27943a41000847221d)\n\n\n## Current Drawbacks\n1. All values are translated to strings in JSON\n2. There are currently reserved words in the JSON converter: \n    * \"content\" - up to version 1.2.3\n    * \"children\"\n\n### Default Mapping & Collisions\n\nBy default, an element's **text content** is mapped to a `\"content\"` property, while its **attributes** are mapped directly to JSON properties of the same name.\n\n#### The Risk\nIf an XML element possesses an attribute actually named `content` while also containing text content, a **name collision** occurs. This typically results in a parsing error or data loss due to duplicate keys.\n\n**Example Collision:**\n```xml\n<MyElement content=\"attr-value\">text-content</MyElement>\n ```\n\n### Version 1.2.3+ Fix\nTo prevent these collisions, versions newer than 1.2.3 will specifically prefix the `\"content\"` attribute name with an `@` symbol. So the attribute `\"content\"` now becomes the `\"@content\"` JSON property.\n\n\n> [!NOTE]\n> If you need to, you can write your own converter from the AST created by the parser, and pass it as a 2nd parameter after the xml string\n","publish_time":1775551576869,"_cnpm_publish_time":1775551576869,"dist-tags":{"latest":"1.2.7"}}