-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsonstat2objarr
77 lines (72 loc) · 2.45 KB
/
jsonstat2objarr
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/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-objarr.json", "converts JSON-stat file oecd.json into a new file (oecd-objarr.json) with a column-oriented data structure.")
.example("$0 < oecd.json > oecd-objarr.json -t", "converts JSON-stat stream oecd.json into a new stream (oecd-objarr.json) with a column-oriented data structure.")
.boolean("s")
.alias("s", "status")
.describe("s", "Include status information")
.alias("v", "vlabel")
.describe("v", "Label of the value field (default is 'Value')")
.alias("a", "slabel")
.describe("a", "Label of the status field (default is 'Status')")
.boolean("f")
.alias("f", "flabel")
.describe("f", "Identify dimensions, value and status by label instead of ID")
.boolean("c")
.alias("c", "cid")
.describe("c", "Identify categories by ID instead of label")
.boolean("u")
.alias("u", "unit")
.describe("u", "Include unit information when available")
.boolean("m")
.alias("m", "meta")
.describe("m", "Use the metadata enriched output (object of objects)")
.alias("b", "by")
.describe("b", "Transpose by the specified dimension")
.boolean("l")
.alias("l", "bylabel")
.describe("l", "Use labels instead of IDs to identify categories of the transposed dimension")
.alias("p", "prefix")
.describe("p", "Prefix to be used when data is transposed")
.alias("d", "drop")
.describe("d", "Comma-separated single category dimensions to be dropped when data is transposed")
.boolean("k")
.alias("k", "comma")
.describe("k", "Represent values as strings with comma as the decimal mark")
.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: "objarr",
vlabel: argv.vlabel,
slabel: argv.slabel,
status: argv.status,
content: argv.cid ? "id": "label",
field: argv.flabel ? "label": "id",
unit: argv.unit,
meta: argv.meta,
by: argv.by,
bylabel: argv.bylabel,
prefix: argv.prefix,
drop: (typeof argv.drop==="undefined") ? [] : argv.drop.split(","),
comma: argv.comma
})
;
if(tbl===null){
console.error("Error: The input does not containt valid JSON-stat.");
process.exit(1);
}
return tbl;
}
;
inout.main(argv, callback);