Pure javascript XML to JSON converter with zero dependencies.
npm install @hendt/xml2json
npm install @hendt/xml2json
`
Usage
$3
`javascript
import xml2json from '@hendt/xml2json';
const xml = 'John Doe ';
const json = xml2json(xml);
console.log(json);
// prints '{"person": {"name": "John Doe"}}'
`
$3
#### Single attribute
`javascript
import xml2json from '@hendt/xml2json';
const xml = 'John Doe ';
const json = parser.xml2json(xml);
console.log(json);
// prints '{"person”: {"id": "1234", "name": "John Doe"}}'
`
#### Multiple attributes
`javascript
import xml2json from '@hendt/xml2json';
const xml = 'John Doe ';
const json = parser.xml2json(xml);
console.log(json);
// prints '{"person”: {"id”: "1234”, "age”: "30”, "name”: "John Doe”}}'
`
$3
#### Orphan values
`javascript
import xml2json from '@hendt/xml2json';
const xml = 'Something ';
// The xml string is converted to :
// 1234 Something '
//
// This line now contains an orphan value
// the xml string is then converted to :
// '1234 <_@ttribute>Something '
const json = xml2json(xml);
console.log(json);
// prints '{"person": {"id": "1234", "_@ttribute": "Something"}}'
`
Custom name:
`javascript
import xml2json from '@hendt/xml2json';
const xml = 'Something ';
const json = xml2json(xml, {aloneValueName: '@value'});
console.log(json);
// prints '{"person": {"id": "1234", "@value": "Something"}}'
`
#### Comments
`javascript
import xml2json from '@hendt/xml2json';
const xml = ' Jane Doe ';
// The xml string is converted to :
// Jane Doe
// All comments will be removed
const json = xml2json(xml);
console.log(json);
// prints '{"name": "Jane Doe"}'
``