npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

kiss-xml-json-mapper

v0.1.7

Published

Maps XML documents into JSON

Downloads

21

Readme

KISS XML JSON Mapper

Takes an JSON definition ...

{
  "soapenv:Envelope|envelope": {
    "soapenv:Header|header" : {
      "ebl:RequesterCredentials|credentials": {
        "ebl:NotificationSignature|signature": "string"
      }
    },
    "soapenv:Body|body" : {
      "GetItemResponse|content": {
        "Timestamp|timestamp": "datetime",
        "Item|item": {
          "BuyerProtection|buyerProtection": "string",
          "Description|description": "string"
        }
      }
    }
  }
}

And an XML document ...

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <ebl:RequesterCredentials soapenv:mustUnderstand="0" xmlns:ns="urn:ebay:apis:eBLBaseComponents" xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
            <ebl:NotificationSignature xmlns:ebl="urn:ebay:apis:eBLBaseComponents">2MMvMmzJ1WW3UJkmesy5/g==</ebl:NotificationSignature>
        </ebl:RequesterCredentials>
    </soapenv:Header>
    <soapenv:Body>
        <GetItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
            <Timestamp>2020-05-16T14:33:44.328Z</Timestamp>
            <Ack>Success</Ack>
            <CorrelationID>755553470</CorrelationID>
            <Version>1143</Version>
            <Build>E1143_CORE_APIMSG_19169581_R1</Build>
            <NotificationEventName>BidReceived</NotificationEventName>
            <RecipientUserID>testuser_granson</RecipientUserID>
            <EIASToken>nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4aiC5OHqASdj6x9nY+seQ==</EIASToken>
            <Item>
                <AutoPay>false</AutoPay>
                <BuyerProtection>ItemIneligible</BuyerProtection>
                <BuyItNowPrice currencyID="USD">18.0</BuyItNowPrice>
                <Country>US</Country>
                <Currency>USD</Currency>
                <Description>
                    This is the fourth book in the Harry Potter series. In excellent condition!
                </Description>
            </Item>
        </GetItemResponse>
    </soapenv:Body>
</soapenv:Envelope>

And returns ...

{
  "envelope": {
    "header" : {
      "credentials": {
        "signature": "2MMvMmzJ1WW3UJkmesy5/g=="
      }
    },
    "body" : {
      "content": {
        "timestamp": "2020-05-16T14:33:44.328Z",
        "item": {
          "buyerProtection": "ItemIneligible",
          "description": "This is the fourth book in the Harry Potter series. In excellent condition!"
        }
      }
    }
  }
}

##Template Definition

The JSON schema template ..

####Property Names

Property names are pipe delimited ...

| Part | Description | | ----------- | ----------- | | 1 | XML attrbute name including the namespace (if any) | | 2 | translated JSON property name|

Where the XML attribute name is suffixed with an asterisk, then it identifys that this a a reurring field - and will result in a array of values. This notation will work at the object level and the propery level.

####Static Properties

To inject a static value into a resolved object - prefix the property name is an exclamation point (!).

      "GetItemResponse|content": {
        "!_kind": "GetItemResponse", // EXAMPLE HERE
        "Timestamp|timestamp": "datetime",
        "Ack|acknowledge": "string",
        "CorrelationID|correlationId": "integer",
        "Item|item": {
          "BuyerProtection|buyerProtection": "string",
          "Description|description": "string"
        }
      }

This will return an object that contains the literal value of the property ...

{
    "content": {
      "_kind": "GetItemResponse", // 
      "timestamp": "2020-05-16T14:33:44.328Z",
      "acknowledge": "Success",
      "correlationId": 755553470,
      "item": {
        "buyerProtection": "ItemIneligible",
        "description": "This is the fourth book in the Harry Potter series. In excellent condition!"
      }
    }
}

####Property Values

A property value is either an object that describes an embedded value, or it's a terminal value datatype ...

| Name | Description | | ----------- | ----------- | | integer | Translates the XML value to an integer | | float | Translates the XML value to a float | | string | Translates the XML value to a string | | text | Translates the XML value to a string | | datetime | Translates the XML value formatted as an ISO8601 date into a Date value |

##Usage

const schema = {
  "soapenv:Envelope|envelope": {
    "soapenv:Header|header" : {
      "ebl:RequesterCredentials|credentials": {
        "ebl:NotificationSignature|signature": "string"
      }
    },
    "soapenv:Body|body" : {
      "GetItemResponse|content": {
        "Timestamp|timestamp": "datetime",
        "Item|item": {
          "BuyerProtection|buyerProtection": "string",
          "Description|description": "string"
        }
      }
    }
  }
}

const xml = fs.readFileSync('./sample.xml','utf-8')

// Compile the schema into -- if calling multiple times, then cache this value 
const rdr = createReader(schema)

// Translate document
const json = rdr(xml)