How to use xml2json - 10 common examples

To help you get started, we’ve selected a few xml2json examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GianlucaGuarini / nodejs-push-notification-server / server.js View on Github external
fs.readFile(__dirname + '/example.xml', function(err, data) {
      if (err) throw err;
      // parsing the new xml data and converting them into json file
      var json = parser.toJson(data);
      // send the new data to the client
      socket.volatile.emit('notification', json);
    });
  });
github CleverCloud / wadl2json / wadl2json.js View on Github external
exports.fromString = function(wadlString, options) {
    /* Remove XML header as xml2json is not able to parse it */
    wadlString = wadlString.replace(/<\?[^<]*\?>/g, "");
    var wadlJson = parser.toJson(wadlString, {
      object: true,
      arrayNotation: true
    });

    return wadl2json.fromJSON(wadlJson, options);
  };
github segment-boneyard / google-spreadsheets / lib / request.js View on Github external
request.post(req, function (err, res, body) {
    if (err) return callback(err);
    var json = parser.toJson(body, { object: true });
    var entries = json.feed.entry;
    // Google response for a single cell isn't an array
    if (queries.length === 1) entries = [entries];
    var cells = entries.map(function (entry) {
      var cell = entry['gs:cell'];
      return {
        row: cell.row,
        column: cell.col,
        value: cell.inputValue,
        numeric: cell.numericValue,
        text: cell.$t
      };
    });
    return callback(null, cells);
  });
  return this;
github posm / posm-replay-tool / generate-osc.js View on Github external
}, (err, rsp, xml) => {
      if (err) {
        tasks.forEach(x => x.callback(err));

        return next(err);
      }

      if (rsp.statusCode !== 200) {
        err = new Error("Request returned " + rsp.statusCode);

        tasks.forEach(x => x.callback(err));

        return next(err);
      }

      const body = xml2json.toJson(xml, {
        arrayNotation: true, // ensure we get consistent results regardless of the number of results
        // returned
        object: true,
      });

      const versions = body.osm[0][OSM_ENTITY_TYPES[entityType]].reduce((obj, entity) => {
        obj[entity.id] = entity.version;

        return obj;
      }, {});

      tasks.forEach(x => {
        if (versions[x.id]) {
          return x.callback(null, versions[x.id]);
        }
github elifesciences / elife-xpub / scripts / checkNumberOfTestsRun.js View on Github external
const doCheck = (xmlFile, minNumber) => {
  const xml = fs.readFileSync(xmlFile, 'utf8')
  const info = JSON.parse(xml2json.toJson(xml))
  const number = Number(info.testsuites.tests)
  console.info(`Executed ${number} tests`)
  process.exit(number >= minNumber ? 0 : 2)
}
github GetPublii / Publii / app / back-end / modules / import / wxr-parser.js View on Github external
parseFile() {
        let results = false;
        try {
            results = xmlParser.toJson(this.fileContent);
            results = JSON.parse(results);
        } catch(e) {
            console.log('An error occurred:', e);
            return false;
        }

        this.parsedContent = results;

        return true;
    }
github atheed / CricAPI / api / server.js View on Github external
request(url, function (error, response, html) {
        var json = parser.toJson(url); //returns a string containing the JSON structure by default
        console.log(json);
        res.send('Check your console!');
    });
});
github sys1yagi / Goat-Reader / routes / handler / TestHandler.js View on Github external
.on("end", function () {
                        try {
                            var json = parser.toJson(rss);
                            var jsonObject = JSON.parse(json);

                            res.write(json);
                            res.end();
                        } catch (e) {
                            console.log(e);
                        }
                    });
                ;
github guaka / mediawikixml2meteor2phonegap / xml2json.js View on Github external
fs.readFile('dumps/' + wiki + '.xml', function(err, data) {
  var xml = data;
  console.log ('xml size:', data.length);

  var json = parser.toJson(xml, { sanitize: false, trim: false });
  console.log('json size:', json.length);

  var js = "var jsondump = " + json;

  fs.writeFile('dumps/' + wiki + '.js', js, function(err) {
    if (err) {
      throw err;
    }
    console.log('saved');
  });
});
github pact-foundation / pact-js / examples / v3 / todo-consumer / src / todo.js View on Github external
.then(response => {
        console.log("todo response:")
        eyes.inspect(response.data)
        if (format === "xml") {
          const result = JSON.parse(parser.toJson(response.data))
          return result.projects.project
        } else {
          return response.data
        }
      })
      .catch(error => {

xml2json

Converts xml to json and vice-versa, using node-expat.

MIT
Latest version published 4 years ago

Package Health Score

53 / 100
Full package analysis

Popular xml2json functions

Similar packages