Socket
Book a DemoInstallSign in
Socket

faketoe

Package Overview
Dependencies
Maintainers
3
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faketoe

XML to JSON converter

latest
Source
npmnpm
Version
2.1.1
Version published
Maintainers
3
Created
Source

faketoe Logo

XML to JSON converter

Build Status

Lead Maintainer: Nathan LaFreniere

Description

faketoe is a simple Node transformation stream for used to convert an XML stream to a JSON object. It is a thin wrapper around node-expat and supports the same interface and events as a node-expat object.

Usage

var Fs = require('fs');
var FakeToe = require('./lib');

var parser = FakeToe.createParser(function (error, result) {
    // `result` is:
    // {
    //     item: {
    //             name: '1',
    //         property: 'a',
    //            child: [
    //             [0] {
    //                     name: '2',
    //                 property: 'a',
    //                    child: [
    //                     [0] {
    //                             name: '3',
    //                         property: 'a'
    //                     },
    //                     [1] {
    //                         name: '4'
    //                     }
    //                 ]
    //             },
    //             [1] {
    //                 name: '5'
    //             }
    //         ],
    //          goblins: {
    //             goblin: [
    //                 [0] {
    //                     type: 'ear'
    //                 },
    //                 [1] {
    //                     type: 'nose'
    //                 },
    //                 [2] {
    //                     type: 'throat'
    //                 }
    //             ]
    //         },
    //                x: {
    //               y: [
    //                 [0] 'a',
    //                 [1] 'b',
    //                 [2] 'c'
    //             ]
    //         },
    //            extra: {
    //             extended: 'yes'
    //         },
    //                z: {
    //             verbose: 'no',
    //               $text: 'a'
    //         }
    //     }
    // }

});

parser.on('text', function (text) {

    console.log('text event: ' + text);
});

parser.on('endElement', function (name) {

    console.log('end element event: ' + name);
});

Fs.createReadStream(__dirname + '/test/test1.xml').pipe(parser);

Methods

####createParser(callback) creates an XML to JSON parser (stream). The callback function signature is function (error, result) where

  • error - internal error condition
  • result - the complete JSON object

Keywords

xml

FAQs

Package last updated on 08 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts