Skip to content

Commit a75d9e4

Browse files
authored
Update EXAMPLES.md
1 parent 03b519e commit a75d9e4

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

docs/EXAMPLES.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [A Norwegian Example](#a-norwegian-example)
88
* [An Irish Example](#an-irish-example)
99
* [A Danish Example](#a-danish-example)
10+
* [An OECD Example](#an-oecd-example)
1011

1112
Please, read the examples in order: **their requirements are incremental**.
1213

@@ -84,7 +85,7 @@ jsonstat2csv eurostat.jsonstat eurostat-semi.csv --column ";"
8485
jsonstat2csv eurostat.jsonstat eurostat-status.csv --status --vlabel rate --slabel symbol
8586
```
8687

87-
**jsonstat2csv** also allows you to create a rich CSV document with extra metadata header lines ([CSV-stat](https://github.com/badosa/CSV-stat)).
88+
**jsonstat2csv** also allows you to create a rich CSV document with extra metadata header lines ([CSV-stat](https://github.com/jsonstat/csv)).
8889

8990
```
9091
jsonstat2csv eurostat.jsonstat eurostat.jsv --rich
@@ -811,3 +812,71 @@ On Windows:
811812
```
812813
curl "https://api.statbank.dk/v1/data/LIVO1/JSONSTAT?lang=en&Tid=2010%2C2017&AKTP=*" | jsonstat2arrobj -b Tid -l -d ContentsCode -t | ndjson-split | ndjson-format > dk.txt "${this['2017']>this['2010'] ? '\u2191' : '\u2193'} ${this['AKTP']}: ${this['2017']} (${this['2017']>this['2010'] ? '+' : ''}${(this['2017']-this['2010']).toFixed(1)})"
813814
```
815+
816+
## An OECD Example
817+
818+
The OECD does not support JSON-stat: it serves data in the SDMX-JSON format. But jsonstat-conv can convert SDMX-JSON into JSON-stat and benefit from all the tools available for JSON-stat (at the time of writing, they were still very few tools available supporting SDMX-JSON).
819+
820+
In this example, we will be doing several translations.
821+
822+
### Steps
823+
824+
#### 1. Retrieve some key economic indicators from OECD
825+
826+
```
827+
curl "https://stats.oecd.org/SDMX-JSON/data/KEI/PS+PR+PRINTO01+SL+SLRTTO01+SLRTCR03+OD+ODCNPI03+CI+LO+LOLITOAA+LORSGPRT+LI+LF+LFEMTTTT+LR+LRHUTTTT+LC+LCEAMN01+UL+ULQEUL01+PP+PI+CP+CPALTT01+FI+MA+MABMM301+IR+IRSTCI01+IR3TIB01+IRLTLT01+SP+SPASTT01+CCUSMA02+XT+XTEXVA01+XTIMVA01+BP+B6BLTT02+NA+NAEXKP01+NAEXKP02+NAEXKP03+NAEXKP04+NAEXKP06+NAEXKP07.AUS+AUT+BEL+CAN+CHL+CZE+DNK+EST+FIN+FRA+DEU+GRC+HUN+ISL+IRL+ISR+ITA+JPN+KOR+LVA+LTU+LUX+MEX+NLD+NZL+NOR+POL+PRT+SVK+SVN+ESP+SWE+CHE+TUR+GBR+USA+EU28+G-7+OECDE+G-20+OECD+NMEC+ARG+BRA+CHN+COL+IND+IDN+RUS+SAU+ZAF.GP.M/all?startTime=2018-01&endTime=2020-01&dimensionAtObservation=allDimensions" -o kei.sdmx.json
828+
```
829+
830+
This line of code produces an SDMX-JSON file. The size of _kei.sdmx.json_ is 393 Kb.
831+
832+
#### 2. Convert SDMX-JSON to JSON-stat
833+
834+
**sdmx2jsonstat** can be used to translate SDMX-JSON into JSON-stat.
835+
836+
```
837+
sdmx2jsonstat kei.sdmx.json default.stat.json
838+
```
839+
840+
The JSON-stat file is smaller (232 Kb) than the original SDMX-JSON one. An even smaller file can be produced: by default, **sdmx2jsonstat** uses arrays to express values and statuses. JSON-stat supports both arrays and objects for this purpose. Because usually only a few data have status information, it is generally better to use an object for statuses.
841+
842+
**sdmx2jsonstat** supports objects for status information using the _--ostatus_ option (_-s_).
843+
844+
```
845+
sdmx2jsonstat kei.sdmx.json kei.stat.json -s
846+
```
847+
848+
The new JSON-stat file is now only 168 Kb: less than half the original SDMX-JSON one.
849+
850+
#### 3. Convert JSON-stat to CSV
851+
852+
Because now we have a regular JSON-stat file, it is trivial to convert it to CSV, a format that can be used to import the data in many tools.
853+
854+
```
855+
jsonstat2csv kei.stat.json kei.csv
856+
```
857+
858+
The new file is very big (1,174 Kb) because by default labels, instead of identifiers, are used. **jsonstat2csv** has several options to avoid this. But you don’t actually has to choose between labels or identifiers (each serves a different purpose): you can use the ([CSV-stat](https://github.com/jsonstat/csv)) format as the output format: CSV-stat supports the core semantics of JSON-stat using an enriched CSV structure.
859+
860+
You can produce CSV-stat with the _--rich_ option (_-r_):
861+
862+
```
863+
jsonstat2csv kei.stat.json kei.rich.csv -r
864+
```
865+
866+
This command produces a 510 Kb file.
867+
868+
#### 4. Back to JSON-stat
869+
870+
```
871+
csv2jsonstat kei.rich.csv default.json
872+
```
873+
874+
The size of the new JSON-stat is 231 Kb: it is a little smaller than the original JSON-stat had some extension information that was lost in CSV-stat.
875+
876+
This file can be minimized using objects for statuses, thanks to **jsonstat2jsonstat**:
877+
878+
```
879+
jsonstat2jsonstat default.json kei.json -m -s
880+
```
881+
882+
The size of the resulting file is 167 Kb.

0 commit comments

Comments
 (0)