https://github.com/pacificcommunity/sdmx-json-parser
JavaScript SDMX JSON parser
https://github.com/pacificcommunity/sdmx-json-parser
javascript json sdmx
Last synced: about 2 months ago
JSON representation
JavaScript SDMX JSON parser
- Host: GitHub
- URL: https://github.com/pacificcommunity/sdmx-json-parser
- Owner: PacificCommunity
- Created: 2023-02-10T04:38:56.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-21T22:32:20.000Z (over 2 years ago)
- Last Synced: 2025-04-06T00:04:06.733Z (about 1 year ago)
- Topics: javascript, json, sdmx
- Language: JavaScript
- Homepage: https://pacificcommunity.github.io/sdmx-json-parser/
- Size: 863 KB
- Stars: 1
- Watchers: 12
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SDMX-JSON parser
A JavaScript library to parse [SDMX-JSON](https://github.com/sdmx-twg/sdmx-json) messages.
## Installation
```bash
npm install sdmx-json-parser
```
## Usage
SDMX-JSON-parser provides a set of utility function to parse a SDMX-JSON message and extract data arrays.
The method `getDataset` must be called prior to using any other method. It takes a SDMX REST URL as first parameter and an optional `fetchOptions` object as second parameter ([doc](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options)). This fetch options can be used for instance to pass custom headers to the request like `Accept-language` to select the response language.
Every SDMX concepts (observation, dimensions, attributes) are given at observation level in the different methods (getData, getAttributes, getDimensions).
When observations are organized in `series` within a `dataSet`, the parser expand them as an array of `observations` concatenating the keys.
```javascript
import { SDMXParser } from sdmx-json-parser;
const sdmxDataUrl = "https://stats-nsi-stable.pacificdata.org/rest/data/SPC,DF_IMTS,4.0/M..AMT.TB+X+M.IV+I+II+III._T._T.USD?startPeriod=2015-01&dimensionAtObservation=AllDimensions";
const parser = new SDMXParser();
await parser.getDataset(sdmxDataUrl);
const name = parser.getName();
const description = parser.getDescription();
const dimensions = parser.getDimensions();
const activeDimensions = parser.getActiveDimensions();
const annotations = parser.getAnnotations();
const observations = parser.getObservations();
data = sdmx.getData(); // returns a simplified array of observations with dimension and attributes values
const slicedData = parser.getData({GEO_PICT: ['NR']}); // slice by dimension Id (GEO_PICT) values (['NR'])
```
## Example
Go to `examples/vanilla-js` folder and run a local server to see the example.
```bash
npm run server
```
## Developer
### Install dependencies
```bash
npm install
```
### Build with webpack
```bash
npm run build
```
### Generate documentation
```bash
npm run generate-doc
```