0.1.2 • Published 3 years ago

easy-xml2json v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

easy-xml2json

An easy to use XML to JSON converter.

Install

npm i easy-xml2json

# or

yarn add easy-xml2json

Usage

Dead simple to use:

Using ES modules:

import { convertToJson } from 'easy-xml2json'

const testXml = `
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type="text/xsl" href="message-headers.xsl"?>
<?oxygen RNGSchema="message-headers.rng" type="xml"?>
<registry id="perm-headers">
    <title>
    Permanent Message Header Field Names
    </title>
    <xref type="rfc" data="rfc3864"/>    
    <!-- <xref type="rfc" data="rfc5504"/>
      specified that no new header -->
    <record>
        <value>A-IM</value>
        <protocol>http</protocol>
        <xref type="rfc" data="rfc4229"/>
    </record>
    <record>
        <value>Accept-Additions</value>
        <protocol>http</protocol>
        <xref type="rfc" data="rfc4229"/>
    </record>
</registry>
`

// the xml has to be passed in as a string
const jsonOutput = convertToJson(testXml)

Using commonjs:

const { convertToJson } = require('easy-xml2json')
const fs = require('fs/promises')
const testXml = ``

// the xml has to be passed in as a string
const jsonOutput = fs.readFile('file.xml', 'utf8').then(convertToJson)

Using CDN:

<script>
  import { convertToJson } from 'https://cdn.jsdelivr.com/npm/paulebose/easy-xml2json'

  // the xml has to be passed in as a string
  fetch('path.xml')
    .then((res) => res.text())
    .then(convertToJson)
</script>

Advanced

You can pass in additional options to configure the json output.

convertToJson(xmlAsString, {})

Read the documentation.

Contributing

Feel like contributing? That's awesome! There is a contributing guide to help you.

Development

To get started:

  • fork and clone repo
  • run npm i

See contributing guide for more information.

License

MIT © Paul Ebose

0.1.2

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.1

3 years ago