-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToJSON.gs
More file actions
27 lines (26 loc) · 748 Bytes
/
ToJSON.gs
File metadata and controls
27 lines (26 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function responseToJson_(response) {
var xml = XmlService.parse(response);
return xmlToJson_(xml.getRootElement());
}
function xmlToJson_(element) {
var result = {};
var children = element.getChildren();
if (children.length == 0) {
result = element.getValue();
} else {
for (var i=0; i<children.length; i++) {
var child = children[i];
var name = child.getName();
var value = xmlToJson_(child);
if (name == 'service' || name == 'callingPointList' || name == 'callingPoint' || name == 'location') {
if (typeof result[name] === "undefined") {
result[name] = [];
}
result[name].push(value);
} else {
result[name] = value;
}
}
}
return result;
}