Skip to content

Commit ab8a1ca

Browse files
committed
1.5.0
New jsonstat2csv options: --by and --drop
1 parent 026758b commit ab8a1ca

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

docs/API.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,25 @@ String. Decimal separator. Default is ".", unless column separator is ";" (then
359359
jsonstat2csv oecd.json oecd.tsv --column "\t" --decimal ","
360360
```
361361

362+
#### --by (-y)
363+
364+
String. Dimension ID. When a valid dimension ID is provided, the resulting CSV is transposed by that dimension and the value column is replaced by as many columns as categories in the specified dimension.
365+
366+
When this option is set with a valid ID, **--status**, **--vlabel** and **--slabel** are ignored. When **--rich** is set or an invalid ID is specified, **--by** is ignored.
367+
368+
#### --drop (-o)
369+
370+
String. Comma-separated list of dimension IDs. When a valid dimension ID is provided in **--by** parameter, ***drop*** can provide a list of constant dimension IDs to remove from the resulting CSV.
371+
372+
```
373+
jsonstat2csv eurostat.json eurostat.csv --by unit --drop freq,age
374+
```
375+
362376
#### --rich (-r)
363377

364378
Boolean. Output is a rich CSV in the [JSON-stat Comma-Separated Values format](https://github.com/jsonstat/csv) (CSV-stat, or JSV for short). CSV-stat is CSV plus a metadata header. CSV-stat supports all the JSON-stat dataset core semantics. This means that CSV-stat can be converted back to JSON-stat (using [csv2jsonstat](#csv2jsonstat)) without loss of information (only the *note*, *link*, *child*, *coordinates* and *extension* properties are not currently supported).
365379

366-
When this option is set, **--status**, **--vlabel** and **--slabel** are ignored.
380+
When this option is set, **--status**, **--vlabel**, **--slabel**, **--by** and **--drop** are ignored.
367381

368382
```
369383
jsonstat2csv oecd.json oecd.jsv --rich

jsonstat2csv

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ var
2525
.describe("v", "Label of the value field (default is 'Value')")
2626
.alias("l", "slabel")
2727
.describe("l", "Label of the status field (default is 'Status')")
28+
.alias("y", "by")
29+
.describe("y", "Dimension to transposed by")
30+
.alias("o", "drop")
31+
.describe("o", "Comma-separated list of constant dimensions to remove when a valid 'by' is specified.")
2832
.boolean("b")
2933
.alias("b", "big")
3034
.describe("b", "This is an emergency option only to be used when the stream interface is not enabled and the dataset is very big.")
@@ -50,7 +54,9 @@ var
5054
na: argv.na,
5155
delimiter: (argv.column==="\\t") ? "\t" : argv.column,
5256
separator: (argv.unit==="\\t") ? "\t" : argv.unit,
53-
decimal: argv.decimal
57+
decimal: argv.decimal,
58+
by: argv.by,
59+
drop: argv.drop ? argv.drop.split(",") : []
5460
}
5561
)
5662
;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsonstat-conv",
3-
"version": "1.4.2",
3+
"version": "1.5.0",
44
"description": "JSON-stat Command Line Conversion Tools",
55
"homepage": "https://github.com/jsonstat/conv",
66
"keywords": [
@@ -42,7 +42,7 @@
4242
},
4343
"license": "Apache-2.0",
4444
"dependencies": {
45-
"jsonstat-suite": "^3.2.5",
45+
"jsonstat-suite": "^3.5.0",
4646
"jsonstat-toolkit": "^1.4.2",
4747
"rw": "^1.3.3",
4848
"yargs": "^15.1.0",

0 commit comments

Comments
 (0)