-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsonstat2array
More file actions
executable file
·52 lines (47 loc) · 1.49 KB
/
jsonstat2array
File metadata and controls
executable file
·52 lines (47 loc) · 1.49 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
var
argv=require("yargs")
.version()
.usage("Usage:\n $0 [input filename] [output filename]\n $0 < [input] > [output] -t")
.example("$0 oecd.json oecd-array.json", "converts JSON-stat file oecd.json into a new file (oecd-array.json) containing an array of arrays.")
.example("$0 < oecd.json > oecd-array.json -t", "converts JSON-stat stream oecd.json into a new stream (oecd-array.json) containing an array of arrays.")
.boolean("s")
.alias("s", "status")
.describe("s", "Include status information")
.alias("v", "vlabel")
.describe("v", "Label of the value field (default is 'Value')")
.alias("l", "slabel")
.describe("l", "Label of the status field (default is 'Status')")
.boolean("f")
.alias("f", "fid")
.describe("f", "Identify dimensions, value and status by ID instead of label")
.boolean("c")
.alias("c", "cid")
.describe("c", "Identify categories by ID instead of label")
.boolean("t")
.alias("t", "stream")
.describe("t", "Enable the stream interface")
.help("h")
.alias("h", "help")
.argv
,
inout=require("./inout"),
callback=function(contents){
var
tbl=inout.dataset(contents).toTable({
type: "array",
vlabel: argv.vlabel,
slabel: argv.slabel,
status: argv.status,
content: argv.cid ? "id": "label",
field: argv.fid ? "id": "label"
})
;
if(tbl===null){
console.error("Error: The input does not containt valid JSON-stat.");
process.exit(1);
}
return tbl;
}
;
inout.main(argv, callback);