### Install ndjson-cli Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Installs the ndjson-cli package globally, which provides tools for processing newline-delimited JSON. ```bash npm install -g ndjson-cli ``` -------------------------------- ### Install ndjson-format Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Installs the ndjson-format npm package globally, which is used for formatting NDJSON data with ES2015 template literals. ```bash npm install -g ndjson-format ``` -------------------------------- ### Example CSV Output Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Demonstrates the content of a CSV file after converting the transformed JSON data, with 'time' and 'ratio' columns. ```csv time,ratio 2009M01,0.9332460732984292 2009M02,0.9357798165137616 2009M03,0.938722294654498 2009M04,0.9384010484927916 2009M05,0.9407894736842105 2009M06,0.9446640316205533 2009M07,0.9455511288180611 2009M08,0.9454787234042552 2009M09,0.9476510067114093 2009M10,0.946524064171123 ... ``` -------------------------------- ### Install jsonstat-conv Source: https://github.com/jsonstat/conv/blob/master/README.md Installs the JSON-stat Command Line Conversion Tools globally using npm. ```bash npm install -g jsonstat-conv ``` -------------------------------- ### Example JSON-stat Data Structure Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md An example of the initial JSON-stat data structure, where each record contains values for a specific combination of categories. ```json [ { "time": "2009", "geo": "Austria", "sex": "Total", "unit": "Percentage of population in the labour force", "age": "From 15 to 74 years", "freq": "Annual", "value": 5.7 }, ... ] ``` -------------------------------- ### Check jsonstat-conv Version Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md This command is used to check the installed version of the jsonstat-conv tool. ```bash jsonstat2csv --version ``` -------------------------------- ### Install jsonstat-conv Source: https://github.com/jsonstat/conv/blob/master/docs/INSTALL.md Installs the jsonstat-conv package globally using npm. This command requires Node.js and npm to be installed on the system. ```bash npm install -g jsonstat-conv ``` -------------------------------- ### Convert SDMX-JSON to JSON-stat using sdmx2jsonstat Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Demonstrates the conversion of an SDMX-JSON file to the JSON-stat format using the 'sdmx2jsonstat' tool. Two examples are provided: a default conversion and a conversion using the '--ostatus' option for more compact status representation. ```bash sdmx2jsonstat kei.sdmx.json default.stat.json ``` ```bash sdmx2jsonstat kei.sdmx.json kei.stat.json -s ``` -------------------------------- ### Prepare Time Array for Visualization Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Extracts and formats the 'time' field from NDJSON data to create a time array for visualization, slicing the string to get year and month. ```bash ndjson-map "d.time.slice(0,4)+d.time.slice(5,7)" < no-ratio.ndjson | ndjson-reduce > time.json ``` -------------------------------- ### Example Transformed JSON Data Structure Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Shows the desired JSON structure after data transformation, containing 'time' and 'ratio' fields. ```json { "time": "2006M02", "ratio": 0.8996036988110964 } ``` -------------------------------- ### NDJSON Transformation with ndjson-format Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Shows how to pipe data through ndjson-split and ndjson-format to transform NDJSON content using a JavaScript template literal. Includes examples for both Unix-like systems and Windows due to differing quote handling. ```bash ndjson-split < dk.json | ndjson-format > dk.txt '${this["2017"]>this["2010"] ? "\u2191" : "\u2193"} ${this["AKTP"]}: ${this["2017"]} (${this["2017"]>this["2010"] ? "+" : ""}${(this["2017"]-this["2010"]).toFixed(1)})' ``` ```bash ndjson-split < dk.json | ndjson-format > dk.txt "${this['2017']>this['2010'] ? '\u2191' : '\u2193'} ${this['AKTP']}: ${this['2017']} (${this['2017']>this['2010'] ? '+' : ''}${(this['2017']-this['2010']).toFixed(1)})" ``` -------------------------------- ### Prepare Data Array for Visualization Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Extracts the 'ratio' field from NDJSON data to create a data array for visualization. ```bash ndjson-map "d.ratio" < no-ratio.ndjson | ndjson-reduce > data.json ``` -------------------------------- ### Sample JSON Output (Default Naming) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md An example of the JSON output generated by jsonstat2arrobj when using default category naming. It shows data points with associated dimension labels. ```json [ { "0": 71.4, "1": 75, "2": 67.7, "Alder": "15-74 years", "ContentsCode": "Labour force in per cent of the population", "Justering": "Seasonally adjusted", "Tid": "2006M02" }, ... ] ``` -------------------------------- ### Download UNECE Data Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Downloads a JSON-stat dataset from UNECE using curl, specifying the output file name. This is the first step for processing UNECE data. ```bash curl https://w3.unece.org/PXWeb2015/sq/6c97a19a-d916-444e-93d9-1c2e951351d8 -o unece.jsonstat ``` -------------------------------- ### Example Data Array for Visualization Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Represents the 'data' array format expected by the Visual Maker for line charts, containing numerical values. ```json [ 2009M01,0.9332460732984292, 2009M02,0.9357798165137616, 0.938722294654498, ... ] ``` -------------------------------- ### End-to-End Data Retrieval and Transformation Pipeline Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Combines multiple command-line tools (curl, jsonstat2arrobj, ndjson-split, ndjson-format) to fetch data from an API, convert it to a structured format, and then transform it using a template literal. Examples are provided for both Unix-like and Windows environments. ```bash 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)})' ``` ```bash 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)})" ``` -------------------------------- ### Download Danish Data Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Downloads the quality of life key figures dataset from Statistics Denmark using curl and saves it as a JSON-stat file. ```bash curl "https://api.statbank.dk/v1/data/LIVO1/JSONSTAT?lang=en&Tid=2010%2C2017&AKTP=*" -o dk.jsonstat ``` -------------------------------- ### Download Eurostat Data Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Downloads a JSON-stat dataset from Eurostat using curl and saves it to a file. This is the initial step for data processing. ```bash curl "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/tesem120?lang=en&sex=T" -o eurostat-subset.jsonstat ``` -------------------------------- ### Check jsonstat-conv Version Source: https://github.com/jsonstat/conv/blob/master/docs/INSTALL.md Checks the installed version of the JSON-stat Command Line Conversion Tools. This command is used to verify the installation and the specific version of the tools. ```bash jsonstat2csv --version ``` -------------------------------- ### Sample JSON Output (Category IDs) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md An example of the JSON output generated by jsonstat2arrobj when using the '--cid' option. Category names are replaced by their corresponding IDs, making the structure more concise. ```json [ { "0": 71.4, "1": 75, "2": 67.7, "Alder": "15-74", "ContentsCode": "ArbStyrkProsBefolkn", "Justering": "S", "Tid": "2006M02" }, ... ] ``` -------------------------------- ### Example NDJSON Data Structure Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Illustrates the structure of data after conversion to newline-delimited JSON (NDJSON), where each line is a JSON object. ```json {"0":71.4,"1":75,"2":67.7,"Alder":"15-74","ContentsCode":"ArbStyrkProsBefolkn","Tid":"2006M02", "Justering":"S"} {"0":71.4,"1":74.9,"2":67.7,"Alder":"15-74","ContentsCode":"ArbStyrkProsBefolkn","Tid":"2006M03", "Justering":"S"} {"0":71.4,"1":74.9,"2":67.8,"Alder":"15-74","ContentsCode":"ArbStyrkProsBefolkn","Tid":"2006M04", "Justering":"S"} ... ``` -------------------------------- ### Example Time Array for Visualization Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Represents the 'time' array format expected by the Visual Maker for line charts, containing time identifiers. ```json [ 2009M01, 2009M02, 2009M03, ... ] ``` -------------------------------- ### Download JSON-stat Data using cURL Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Downloads JSON-stat data directly from a Eurostat API URL using the cURL command-line tool. ```bash curl "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/tesem120?lang=en&sex=T" -o eurostat-subset.jsonstat ``` -------------------------------- ### Norway Data Retrieval and Transformation Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Retrieves customized data from the Norwegian statistics API (SSB), transforms it into an array of objects, filters null values, calculates ratios, reduces the data, and converts it to CSV format. This example demonstrates a pipeline for processing specific statistical data. ```bash curl -X POST -d '{ "query": [ { "code": "Kjonn", "selection": { "filter": "item", "values": [ "1", "2" ] } }, { "code": "ContentsCode", "selection": { "filter": "item", "values": [ "ArbstyrkP1" ] } } ], "response": { "format": "json-stat2" } }' https://data.ssb.no/api/v0/en/table/08931 | jsonstat2arrobj -b Kjonn -c -t | ndjson-split | ndjson-filter "d['1']!==null" | ndjson-map "{time: d.Tid, ratio: d['2']/d['1']}" | ndjson-reduce | json2csv > no.csv ``` -------------------------------- ### Ireland Population Data Download Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Downloads the population estimates dataset (PEA01) from the Central Statistics Office (CSO) of Ireland in JSON-stat format. This is the initial step for building a population pyramid for Ireland. ```bash curl https://ws.cso.ie/public/api.restful/PxStat.Data.Cube_API.ReadDataset/PEA01/JSON-stat/2.0/en -o ie.jsonstat ``` -------------------------------- ### Combined Data Processing Pipeline Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md A comprehensive command-line pipeline that fetches data from a URL, processes it through multiple ndjson-cli tools, and converts it to CSV. ```bash curl "https://data.ssb.no/api/v0/dataset/1054.json?lang=en" | jsonstatdice -f ContentsCode=ArbStyrkProsBefolkn,Alder=15-74,Justering=S -t | jsonstat2arrobj -b Kjonn -t | ndjson-split | ndjson-filter "d['0']!==null" | ndjson-map "{time: d.Tid, ratio: d['2']/d['1']}" | ndjson-reduce | json2csv > no.csv ``` -------------------------------- ### Transform NDJSON Data Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Transforms each line of an NDJSON file using a JavaScript expression. This example calculates a ratio between '2' and '1' properties and maps the 'Tid' property to 'time'. ```bash ndjson-map "{time: d.Tid, ratio: d['2']/d['1']}" < no-filtered.ndjson > no-ratio.ndjson ``` -------------------------------- ### Ireland Data Filtering with jsonstatdice (Stream Interface) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md An alternative method for filtering the Ireland population dataset using jsonstatdice with the stream interface. This is useful for processing large files or when chaining commands. It achieves the same filtering as the previous example but operates on data streams. ```bash jsonstatdice < ie.jsonstat > ie-drop.jsonstat --filter C02076V02508=-/320/575/205/215/310/420/505,C02199V02655=- --drop --stream ``` -------------------------------- ### Convert JSON-stat to CSV with Status and Renamed Labels Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md This example shows how to convert JSON-stat to CSV while including status information and renaming the default 'Value' and 'Status' column headers to 'Rate' and 'Symbol' respectively. ```bash jsonstat2csv eurostat.jsonstat eurostat-status.csv --status --vlabel Rate --slabel Symbol ``` -------------------------------- ### Transposed JSON Data Structure Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md An example of the transposed JSON data structure, where country codes (geo) become columns and their corresponding values are stored under these columns. ```json [ { "unit": "Percentage of population in the labour force", "sex": "Total", "age": "From 15 to 74 years", "time": "2009", "AT": 5.7, "BE": 8, "BG": 7.9, "CY": 5.4, ... }, ... ] ``` -------------------------------- ### Retrieve Economic Indicators from OECD using curl Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Fetches key economic indicators from the OECD API in SDMX-JSON format. The command specifies the data, location, time range, and observation dimensions, saving the output to a file named 'kei.sdmx.json'. ```bash 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+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 ``` -------------------------------- ### Filter NDJSON by Value Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Filters lines in an NDJSON file based on a JavaScript condition. This example keeps lines where the '0' property is not null. ```bash ndjson-filter "d['0']!==null" < no.ndjson > no-filtered.ndjson ``` -------------------------------- ### Convert CSV-stat back to JSON-stat Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Demonstrates the reverse process of converting a CSV-stat file (generated with --rich) back into a JSON-stat file using the csv2jsonstat command. ```bash csv2jsonstat eurostat.jsv eurostat-conv.jsonstat ``` -------------------------------- ### Convert JSON-stat to Array of Objects Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md This example shows how to convert JSON-stat data into an array of objects format using the jsonstat2arrobj command. This format is commonly used for data exchange. ```bash jsonstat2arrobj eurostat.jsonstat eurostat.json ``` -------------------------------- ### Reduce NDJSON to JSON Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts an NDJSON file back into a single JSON array of objects using ndjson-reduce. ```bash ndjson-reduce < no-ratio.ndjson > no-ratio.json ``` -------------------------------- ### Convert UNECE JSON-stat to CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a downloaded UNECE JSON-stat file to a CSV file, transposing by 'Country' and dropping the 'Indicator' dimension. This processes a local file. ```bash jsonstat2csv unece.jsonstat unece-transp.csv --by Country --drop Indicator ``` -------------------------------- ### Combined Data Transformation Pipeline Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md A comprehensive command-line pipeline that fetches data using curl, transforms it using jsonstatdice and jsonstat2arrobj, processes it with ndjson-cli, and finally converts it to CSV. ```bash curl https://ws.cso.ie/public/api.restful/PxStat.Data.Cube_API.ReadDataset/PEA01/JSON-stat/2.0/en | jsonstatdice -f C02076V02508=-/320/575/205/215/310/420/505,C02199V02655=- -d -t | jsonstatdice -f "TLIST(A1)"=2022 -t | jsonstat2arrobj -d STATISTIC -b C02199V02655 -l -t | ndjson-split | ndjson-map "{ Age: d['C02076V02508'], Sex: d['C02199V02655'], Male: -1*d.Male, Female: d.Female }" | json2csv -n > ie.csv ``` -------------------------------- ### Ireland Data Filtering with jsonstatdice (Latest Year) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Further filters the Ireland population dataset to keep only the data for the latest year (2022 in this example). This is done using jsonstatdice with a filter on the 'TLIST(A1)' dimension, ensuring only the most recent data is retained for subsequent processing. ```bash jsonstatdice < ie-drop.jsonstat > ie-filtered.jsonstat --filter "TLIST(A1)"=2022 --stream ``` -------------------------------- ### Download Eurostat Data using cURL Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md This snippet shows how to download Eurostat data in JSON-stat format using the cURL command-line tool. It specifies the API endpoint and an output file name. ```bash curl "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/tesem120?lang=en" -o eurostat.jsonstat ``` -------------------------------- ### Convert JSON to CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a JSON file into CSV format. This is a standard way to prepare data for spreadsheet applications. ```bash json2csv < ie-pyram.json > ie.csv ``` -------------------------------- ### Convert JSON-stat to CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Demonstrates converting a JSON-stat file to a CSV file using the jsonstat2csv command. It includes options for specifying the column delimiter and decimal mark. ```bash jsonstat2csv eurostat.jsonstat eurostat.csv ``` ```bash jsonstat2csv eurostat.jsonstat eurostat-semi.csv --column ";" ``` -------------------------------- ### Norway Data Retrieval and Transformation (Windows) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md This is a Windows-specific version of the Norway data processing pipeline. It uses curl with slightly different quoting for the POST data to accommodate Windows command-line environments. The core functionality remains the same: retrieving, transforming, filtering, and converting JSON-stat data. ```bash curl -X POST -d "{ \"query\": [ { \"code\": \"Kjonn\", \"selection\": { \"filter\": \"item\", \"values\": [ \"1\", \"2\" ] } }, { \"code": \"ContentsCode\", \"selection\": { \"filter\": \"item\", \"values\": [ \"ArbstyrkP1\" ] } } ], \"response\": { \"format\": \"json-stat2\" } }" https://data.ssb.no/api/v0/en/table/08931 | jsonstat2arrobj -b Kjonn -c -t | ndjson-split | ndjson-filter "d['1']!==null" | ndjson-map "{time: d.Tid, ratio: d['2']/d['1']}" | ndjson-reduce | json2csv > no.csv ``` -------------------------------- ### Create Rich CSV from JSON-stat Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md This snippet illustrates how to generate a 'rich' CSV file from JSON-stat data, which includes extra metadata header lines. It uses the --rich option of jsonstat2csv. ```bash jsonstat2csv eurostat.jsonstat eurostat.jsv --rich ``` -------------------------------- ### Convert JSON to CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a JSON file into CSV format using the json2csv command, which is part of d3-dsv. ```bash json2csv < no-ratio.json > no.csv ``` -------------------------------- ### Download Statistics Norway Data with cURL Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Downloads a specific dataset (ID 1054) from Statistics Norway's API in JSON-stat format using cURL. This is the initial step to obtain the raw data for further processing. ```bash curl "https://data.ssb.no/api/v0/dataset/1054.json?lang=en" -o no.jsonstat ``` -------------------------------- ### Convert UNECE JSON-stat to Semicolon-Delimited CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a UNECE JSON-stat file to a semicolon-delimited CSV file, specifying the column delimiter. This processes a local file. ```bash jsonstat2csv unece.jsonstat unece-semi.csv --by Country --drop Indicator --column ";" ``` -------------------------------- ### Convert JSON-stat to Array of Objects (Category IDs) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a filtered JSON-stat file ('no-subset.jsonstat') to an array of objects ('no-id.json'), similar to the previous example. The '--cid' option ensures that categories from transposed dimensions (like 'Kjonn') are named using their IDs instead of labels, simplifying subsequent processing. ```bash jsonstat2arrobj no-subset.jsonstat no-id.json --by Kjonn --cid ``` -------------------------------- ### Convert Eurostat JSON-stat to CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a downloaded Eurostat JSON-stat file to a CSV file, transposing by 'geo' and dropping specified dimensions. This command processes a local file. ```bash jsonstat2csv eurostat-subset.jsonstat eurostat-subset.csv --by geo --drop sex,age,unit,freq --fid ``` -------------------------------- ### JavaScript Template Literal for Data Transformation Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Demonstrates how to use ES2015 template literals in JavaScript to format data, including adding directional symbols (up/down arrows), displaying key figures, and calculating value changes with specific formatting. ```js `${this["2017"] > this["2010"] ? "\u2191" : "\u2193"}` ``` ```js `${this["AKTP"]}: ${this["2017"]}` ``` ```js `(${this["2017"] > this["2010"] ? "+" : ""}${(this["2017"]-this["2010"]).toFixed(1)})` ``` ```js `${this["2017"] > this["2010"] ? "\u2191" : "\u2193"} ${this["AKTP"]}: ${this["2017"]} (${this["2017"] > this["2010"] ? "+" : ""}${(this["2017"]-this["2010"]).toFixed(1)})` ``` -------------------------------- ### Minimize JSON-stat file Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Minimizes a JSON-stat file by using objects for statuses, improving efficiency and reducing file size. This is achieved using the jsonstat2jsonstat tool with the '-m' and '-s' options. ```bash jsonstat2jsonstat default.json kei.json -m -s ``` -------------------------------- ### Extract Canada Economic Indicators to CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md A pipeline to extract key economic indicators for Canada from a JSON-stat file and convert it into a CSV format. It involves transposing data, splitting into NDJSON, filtering by location, and finally converting to CSV. ```bash jsonstat2arrobj < kei.json -b SUBJECT -d MEASURE,FREQUENCY -l -t | ndjson-split | ndjson-filter "d['LOCATION']==='Canada'" | json2csv -n > kei-ca.csv ``` -------------------------------- ### Convert Eurostat JSON-stat to Semicolon-Delimited CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts Eurostat JSON-stat data to a semicolon-delimited CSV with a comma as the decimal mark, using a single-line piped command. ```bash curl "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/tesem120?lang=en&sex=T" | jsonstat2csv --by geo --drop sex,age,unit,freq --fid --column ";" --decimal "," --stream > eurostat-subset-semi.csv ``` -------------------------------- ### Convert JSON-stat to CSV with Options (jsonstat2csv) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts JSON-stat data to CSV format, supporting transposition by a dimension, dropping specific dimensions, and requesting dimension IDs instead of labels. ```bash jsonstat2csv eurostat-subset.jsonstat eurostat-subset.csv --by geo --drop sex,age,unit,freq --fid ``` -------------------------------- ### Convert JSON to NDJSON Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a JSON file containing an array of objects into newline-delimited JSON (NDJSON) format using ndjson-split. ```bash ndjson-split < no-id.json > no.ndjson ``` -------------------------------- ### Convert JSON-stat to CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a JSON-stat file to a standard CSV file. By default, it uses labels which can result in larger files. Options are available to optimize file size. ```bash jsonstat2csv kei.stat.json kei.csv ``` -------------------------------- ### Convert JSON to NDJSON Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a JSON file into NDJSON format, which is useful for stream processing. This is a prerequisite for using ndjson-cli tools. ```bash ndjson-split < ie.json > ie.ndjson ``` -------------------------------- ### Convert NDJSON back to JSON Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts data from NDJSON format back into a single JSON file. This is useful when the processed data needs to be in a standard JSON structure. ```bash ndjson-reduce < ie-pyram.ndjson > ie-pyram.json ``` -------------------------------- ### Convert UNECE JSON-stat to Semicolon-Delimited CSV (Streamed) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts UNECE JSON-stat data to a semicolon-delimited CSV with a comma as the decimal mark in a single line, using piped commands and shorthand arguments. ```bash curl https://w3.unece.org/PXWeb2015/sq/6c97a19a-d916-444e-93d9-1c2e951351d8 | jsonstat2csv -y Country -p Indicator -c ";" -t > unece-semi.csv ``` -------------------------------- ### Convert NDJSON to CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts NDJSON data into CSV format. The '-n' option allows json2csv to read NDJSON directly. ```bash json2csv -n < ie-pyram.ndjson > ie.csv ``` -------------------------------- ### Convert JSON to CSV (d3-dsv) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts JSON data to CSV format using the d3-dsv package. It allows specifying custom column delimiters for the output CSV file. ```bash npm install -g d3-dsv ``` ```bash json2csv < eurostat-drop.json > eurostat.csv ``` ```bash json2csv < eurostat-comma.json > eurostat-semi.csv -w ";" ``` -------------------------------- ### Convert JSON-stat to CSV Example Source: https://github.com/jsonstat/conv/blob/master/README.md Demonstrates how to convert a JSON-stat file to CSV format using the jsonstat2csv command. It shows both file input and stream input methods. ```bash curl "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/tesem120" -o unr.jsonstat jsonstat2csv unr.jsonstat unr.csv ``` ```bash curl "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/tesem120" | jsonstat2csv > unr.csv -t ``` -------------------------------- ### Convert UNECE JSON-stat to CSV (Streamed) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts UNECE JSON-stat data to a CSV file in a single line by piping curl output to jsonstat2csv. Uses shorthand arguments for 'by' and 'drop'. ```bash curl https://w3.unece.org/PXWeb2015/sq/6c97a19a-d916-444e-93d9-1c2e951351d8 | jsonstat2csv -y Country -p Indicator -t > unece.csv ``` -------------------------------- ### Convert Danish JSON-stat to JSON Array Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a JSON-stat file into a more common JSON array structure. It transposes data by time, drops constant dimensions, and outputs in stream mode. ```bash jsonstat2arrobj < dk.jsonstat > dk.json --by Tid --label --drop ContentsCode --stream ``` -------------------------------- ### Convert JSON-stat to Array of Objects (Default Naming) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a filtered JSON-stat file ('no-subset.jsonstat') into a more common array of objects format ('no.json'). The '--by Kjonn' option transposes the 'Kjonn' dimension, and categories are named by their labels by default. ```bash jsonstat2arrobj no-subset.jsonstat no.json --by Kjonn ``` -------------------------------- ### Filter JSON-stat Data with jsonstatdice Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Filters a JSON-stat file ('no.jsonstat') to create a subset ('no-subset.jsonstat'). It selects specific categories from the 'ContentsCode', 'Alder', and 'Justering' dimensions, reducing the dataset size for targeted analysis. ```bash jsonstatdice no.jsonstat no-subset.jsonstat --filter ContentsCode=ArbStyrkProsBefolkn,Alder=15-74,Justering=S ``` -------------------------------- ### Customize Array of Objects (jsonstat2arrobj) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Transforms JSON-stat data to an array of objects, allowing customization of the output structure. It supports transposing values by a specified dimension and dropping unnecessary dimensions. ```bash jsonstat2arrobj eurostat.jsonstat eurostat-transp.json --by geo ``` ```bash jsonstat2arrobj eurostat-subset.jsonstat eurostat-drop.json --by geo --drop sex,age,unit,freq ``` ```bash jsonstat2arrobj eurostat-subset.jsonstat eurostat-comma.json --by geo --drop sex,age,unit,freq --comma ``` -------------------------------- ### Filter JSON-stat Data (jsonstatdice) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Filters JSON-stat data based on specified criteria for dimensions like sex, age, and unit. This is useful for creating subsets of data before further processing. ```bash jsonstatdice eurostat.jsonstat eurostat-subset.jsonstat --filter sex=T,age=Y15-74,unit=PC_ACT ``` -------------------------------- ### Convert Eurostat JSON-stat to CSV (Streamed) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts Eurostat JSON-stat data to CSV in a single line by piping curl output to jsonstat2csv. It uses the stream interface for direct processing. ```bash curl "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/tesem120?lang=en&sex=T" | jsonstat2csv --by geo --drop sex,age,unit,freq --fid --stream > eurostat-subset.csv ``` -------------------------------- ### Ireland Data Conversion to Array of Objects Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts the filtered JSON-stat data for Ireland into a more common JSON array of objects format using jsonstat2arrobj. This command transposes the sex dimension and drops the 'STATISTIC' dimension, preparing the data for easier manipulation and visualization. ```bash jsonstat2arrobj < ie-filtered.jsonstat > ie.json --drop STATISTIC --by C02199V02655 --bylabel --stream ``` -------------------------------- ### Convert CSV-stat back to JSON-stat Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a CSV-stat file back into the JSON-stat format. This process may result in a slightly smaller file size if the original JSON-stat contained extension information that is not preserved in CSV-stat. ```bash csv2jsonstat kei.rich.csv default.json ``` -------------------------------- ### Convert JSON-stat to Rich CSV Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Converts a JSON-stat file to a CSV-stat format using the '--rich' or '-r' option. This format is more semantically aligned with JSON-stat and typically results in smaller files compared to standard CSV conversion. ```bash jsonstat2csv kei.stat.json kei.rich.csv -r ``` -------------------------------- ### Ireland Data Filtering with jsonstatdice (Drop Categories) Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Filters the downloaded Ireland population dataset using jsonstatdice. It removes specific age groups and the 'total' sex category that are not needed for a population pyramid. The `--drop` flag indicates that the specified categories should be removed. ```bash jsonstatdice ie.jsonstat ie-drop.jsonstat --filter C02076V02508=-/320/575/205/215/310/420/505,C02199V02655=- --drop ``` -------------------------------- ### Transform Male Values in NDJSON Source: https://github.com/jsonstat/conv/blob/master/docs/EXAMPLES.md Modifies NDJSON data by multiplying the 'Male' field by -1. This is often done to represent data in a specific way for visualization, such as creating pyramid charts. ```bash ndjson-map "{ Age: d['C02076V02508'], Sex: d['C02199V02655'], Male: -1*d.Male, Female: d.Female }" < ie.ndjson > ie-pyram.ndjson ``` -------------------------------- ### Shared Options for JSON-stat Conversion Tools Source: https://github.com/jsonstat/conv/blob/master/docs/API.md Provides common options applicable to all JSON-stat conversion commands. These include displaying help messages, enabling stream processing, and showing the tool's version. ```APIDOC --help (-h) Shows command's help. --stream (-t) Use the stream interface. --version Shows jsonstat-conv version. ``` ```bash jsonstat2csv --help jsonstat2csv < oecd.json > oecd.csv -t jsonstatslice --version ``` -------------------------------- ### JSON-stat Conversion Commands Source: https://github.com/jsonstat/conv/blob/master/README.md Lists the available command-line tools for converting data to and from the JSON-stat format, including their target formats. ```APIDOC arrow2jsonstat Converts an Apache Arrow file to JSON-stat. csv2jsonstat Converts CSV into JSON-stat. jsonstat2array Converts JSON-stat into an array of arrays. jsonstat2arrobj Converts JSON-stat into an array of objects. jsonstat2arrow Converts JSON-stat to the Apache Arrow format. jsonstat2csv Converts JSON-stat into CSV. jsonstat2objarr Converts JSON-stat into an object of column-oriented arrays. jsonstat2object Converts JSON-stat into a DataTable object. jsonstatdice Creates JSON-stat from JSON-stat. jsonstatslice (deprecated) Creates JSON-stat from JSON-stat. sdmx2jsonstat Converts SDMX into JSON-stat. ``` -------------------------------- ### sdmx2jsonstat Options Source: https://github.com/jsonstat/conv/blob/master/docs/API.md Outlines the options available for the sdmx2jsonstat tool, specifically for controlling the output format of 'value' and 'status' properties. ```APIDOC sdmx2jsonstat: --ovalue (-o) Boolean. Includes a "value" property of type object instead of array. --ostatus (-s) Boolean. When status information is available, includes a "status" property of type object instead of array. ``` -------------------------------- ### sdmx2jsonstat Command Usage Source: https://github.com/jsonstat/conv/blob/master/docs/API.md Shows the basic command to convert data from SDMX-JSON format to JSON-stat format. ```bash sdmx2jsonstat sdmx.json stat.json ``` -------------------------------- ### jsonstatslice Command Usage Source: https://github.com/jsonstat/conv/blob/master/docs/API.md Demonstrates the basic usage of the jsonstatslice command to create a JSON-stat subset from an existing JSON-stat file, filtering by specific dimensions and categories. ```bash jsonstatslice oecd.json oecd-subset.json -f area=DE,year=2014 ``` -------------------------------- ### jsonstatslice Filter Syntax Source: https://github.com/jsonstat/conv/blob/master/docs/API.md Illustrates the syntax for specifying filters in the jsonstatslice command, including how to handle dimension and category IDs that may contain spaces. ```bash jsonstatslice jsonstat10.json jsonstat20.json "area"="DE","year"="2014" ``` -------------------------------- ### jsonstat2arrobj Options Source: https://github.com/jsonstat/conv/blob/master/docs/API.md Provides options for the jsonstat2arrobj command, which converts JSON-stat to an array of objects. Options control how dimensions, categories, units, and metadata are represented in the output. ```APIDOC --flabel (-f) Boolean. Identifies dimensions, value and status by label instead of ID. --cid (-c) Boolean. Identifies categories by ID instead of label. --unit (-u) Boolean. Includes unit information in a property called "unit". If the dataset does not include unit information, the value of the "unit" property will be null. --meta (-m) Boolean. Returns a metadata-enriched output (object of objects, instead of array of objects). --comma (-k) Boolean. Represents values as strings instead of numbers with comma as the decimal mark. --by (-b) String. Transposes data by the specified dimension. String must be an existing dimension ID. Otherwise it will be ignored. --bylabel (-l) Boolean. Uses labels instead of IDs to identify categories of the transposed dimension, unless --cid has been specified. --prefix (-p) String. Text to be used as a prefix in the transposed categories. Only valid in combination with --by. --drop (-d) String. Comma-separated dimension IDs to be dropped from the output. Dimensions with more than one category cannot be dropped. Only valid in combination with --by. ``` -------------------------------- ### jsonstat2object Options Source: https://github.com/jsonstat/conv/blob/master/docs/API.md Options for jsonstat2object to customize the output, such as including status information, specifying labels for value and status fields, and using IDs instead of labels for dimensions and categories. ```bash jsonstat2object oecd.json oecd-object.json --status jsonstat2object oecd.json oecd-object.json --vlabel val jsonstat2object oecd.json oecd-object.json --status --slabel stat jsonstat2object oecd.json oecd-object.json --fid jsonstat2object oecd.json oecd-object.json --cid ```