Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (24 sloc) 668 Bytes
layout title icon group
samples
Convert a String from XML to JSON
fa-caret-right
simple

{{ page.title }}

Steps

  1. Create a project utils_xml.
  2. Create a JavaScript service with the name xml2json.js.
  3. Enter the following content:
var xml2json = require('utils/v3/xml');
var response = require('http/v3/response');

var input = '<a><b>text_b</b><c>text_c</c><d><e>text_e</e></d></a>';
var result = xml2json.toJson(input);

console.log(('JSON: ' + result));
response.println(JSON.stringify('JSON: ' + result));

response.flush();
response.close();

For more information, see the API documentation.