0.0.3 • Published 6 years ago

wdf-to-json v0.0.3

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

jm-wdf-to-json

This package contains the code necessary to convert the JangoMail Web DB Format to JSON.

Contributing

Review the Contributing Guidelines before making changes

Install

Latest version

npm install https://bitbucket.org/jangocode/jm-wdf-to-json.git

Specific version

npm install https://bitbucket.org/jangocode/jm-wdf-to-json.git\#0.0.1

(where 0.0.1 is the tagged version)

Example

const wdfToJson = require('jm-wdf-to-json');

let data = 'EmailAddress,FirstName,LastName___ASDF---BREAKjohn@example.comWG0COLWG0JohnWG0COLWG0DoeWG0ROWWG0WANGO-ENDOFDATASTREAM';

try {
  let json = wdfToJson.parse(data);

  console.log(JSON.stringify(json));
} catch (err) {
  console.error(err);
}

Terms

WDF

Web DB Format

Background

When making a connection to a web database, JangoMail uses a custom format to define the header, rows, columns, and data end.

Header

The header is comprised of a comma separated list of strings, with ___ASDF---BREAK appended to the end.

Data

The data is column delimited by WG0COLWG0 and row delimited by WG0ROWWG0.

File End

The end of the file is marked by a final WANGO-ENDOFDATASTREAM.

Example

Using this example:

EmailAddressFirstNameLastName
john@example.comJohnDoe
jane@example.comJaneDoe
alice@example.comAliceSmith

This is how this would represented in WDF (without newline breaks as shown in this example):

EmailAddress,FirstName,LastName___ASDF---BREAK
john@example.comWG0COLWG0JohnWG0COLWG0DoeWG0ROWWG0
jane@example.comWG0COLWG0JaneWG0COLWG0DoeWG0ROWWG0
alice@example.comWG0COLWG0AliceWG0COLWG0SmithWG0ROWWG0
WANGO-ENDOFDATASTREAM

And this is what this module will convert it to:

[
  {
    "EmailAddress": "john@example.com",
    "FirstName": "John",
    "LastName": "Doe"
  },
  {
    "EmailAddress": "jane@example.com",
    "FirstName": "Jane",
    "LastName": "Doe"
  },
  {
    "EmailAddress": "alice@example.com",
    "FirstName": "Alice",
    "LastName": "Smith"
  }
]