forked from isaacs/sax-js
-
Notifications
You must be signed in to change notification settings - Fork 77
/
example.js
35 lines (33 loc) · 945 Bytes
/
example.js
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
28
29
30
31
32
33
34
35
var clarinet = require("clarinet")
var parser = clarinet.parser();
parser.onvalue = function (v) {
console.log("Value: " + v);
};
parser.onkey = function (key) {
console.log("Key: " + key);
};
parser.onopenobject = function (key) {
console.log("New Object, first key: " + key);
}
parser.oncloseobject = function () {
console.log("Close Object");
}
parser.onopenarray = function () {
console.log("New Array");
}
parser.onclosearray = function () {
console.log("Close Array");
}
parser.onend = function () {
console.log('End');
}
parser
.write('{ "firstName": "John", "lastName": ')
.write('"Smith", "age" : 25, "address" : { ')
.write('"streetAddress": "21 2nd Street", "')
.write('city" : "New York", "state" : "NY",')
.write('"postalCode" : "10021" }, "phoneNum')
.write('ber": [ { "type" : "home", "number"')
.write(': "212 555-1234" }, { "type" : "fax')
.write('", "number": "646 555-4567" } ] }')
.close();