JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q28539F
  • License MIT

This package converts xml string into json and returns the json object as output.

Package Exports

  • xmlintojson

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (xmlintojson) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

xmlintojson

This js converts xml string into json object

Instruction

  1. Include/Require the package

var converter = require('xmlintojson');
  1. Pass the xml string to the function and save the json object response
var xml = "<parent><child></child></parent>";
var json = converter(xml);

Output Format

Below is an example xml used to convert into json:

<?xml version="1.0"?>
<catalog>
   <book id="book001">
      <author>Anabelle</author>
      <title>The Famous Party</title>
      <genre>Action</genre>
      <price>99</price>
      <publish_date>1992-10-01</publish_date>
      <description>An interesting action story</description>
   </book>
   <book id="book002">
      <author>Jordan, Manes</author>
      <title>Midnight Train</title>
      <genre>Fantasy</genre>
      <price>98.99</price>
      <publish_date>1983-05-18</publish_date>
      <description>A zombie attack at the train in the midnight
      </description>
   </book>
</catalog>


Converted output:

{
  "xml": {
    "__version": "1.0"
  },
  "catalog": {
    "book": [
      {
        "author": {
          "_text": "Anabelle"
        },
        "title": {
          "_text": "The Famous Party"
        },
        "genre": {
          "_text": "Action"
        },
        "price": {
          "_text": "99"
        },
        "publish_date": {
          "_text": "1992-10-01"
        },
        "description": {
          "_text": "An interesting action story"
        },
        "__id": "book001"
      },
      {
        "author": {
          "_text": "Jordan, Manes"
        },
        "title": {
          "_text": "Midnight Train"
        },
        "genre": {
          "_text": "Fantasy"
        },
        "price": {
          "_text": "98.99"
        },
        "publish_date": {
          "_text": "1983-05-18"
        },
        "description": {
          "_text": "A zombie attack at the train in the midnight"
        },
        "__id": "book002"
      }
    ]
  }
}