SlideShare a Scribd company logo
JSON-stat & JS
the JSON-stat Javascript Toolkit
Xavier Badosa
@badosa
https://xavierbadosa.com
https://json-stat.org
July, 2013
(updated to JSON-stat 2.0 in January, 2016)
The JSON-stat
Ecosystem
format
libs
conn.
schema
Introducing
the
JSON-stat
Javascript
Toolkit
json-stat.com
Introducing
the
JSON-stat
Javascript
Toolkit
It’s a Javascript
library that helps
you dealing with
JSON-stat
responses.
Introducing
the
JSON-stat
Javascript
Toolkit
It offers methods
to easily traverse
the JSON-stat
tree:
Dataset
Dimension
Category
Data
Introducing
the
JSON-stat
Javascript
Toolkit
It uses three
general
properties:
label
length
id
Sample file
the
JSON-stat
Javascript
Toolkit
This URL returns
a JSON-stat dataset
document.
(Collections can contain
several datasets.)
json-stat.org/samples/canada.json
var ds = JSONstat(
"http://json-stat.org/samples/canada.json"
);
if ( ds.length > 0 ) {
…
}
Retrieve a JSON-stat document.
Check the number of elements.
If zero, the service didn’t return
a valid JSON-stat response.
Sync
JSONstat(
"http://json-stat.org/samples/canada.json",
function () {
if ( this.length > 0 ) {
…
}
}
);
Retrieve a JSON-stat document.
Check the number of elements.
If zero, the service didn’t return
a valid JSON-stat response.
Async
$.getJSON(
"http://json-stat.org/samples/canada.json",
function ( obj ) {
var ds = JSONstat( obj );
if ( ds.length > 0 ) {
…
}
}
);
You can also retrieve a JSON-stat document
with your usual bullet-proof framework and
use JSONstat() for what is good for:
dealing with the resulting object.
var ds = JSONstat(
"http://json-stat.org/samples/canada.json"
);
var cl = ds.class;
It contains a dataset (a cube).
ds.class → "dataset"
var ds = JSONstat(
"http://json-stat.org/samples/canada.json"
);
var cl = ds.class;
(Because it’s a dataset response
you don’t need to use the Dataset() method.)
ds === ds.Dataset( 0 ) → true
var dslabel = ds.label;
Get the dataset label.
ds.label → "Population by sex and age group. Canada. 2012"
var dslabel = ds.label;
var nobs = ds.n;
var upd = ds.updated; // new Date(upd) to convert into date
Get the number of data in the dataset
and the update information.
ds.n → 120
ds.updated → "2012-09-27"
var dslabel = ds.label;
var nobs = ds.n;
var upd = ds.updated;
var ndim = ds.length;
var dimid = ds.id;
Get the number of dimensions and
the dimensions’ IDs.
ds.length → 5
ds.id → ["country", "year", "age", "concept", "sex"]
var dslabel = ds.label;
var nobs = ds.n;
var upd = ds.updated;
var ndim = ds.length;
var dimid = ds.id;
var sex = ds.Dimension( 4 );
Let’s analyze dimension “sex”.
Selected by index.
var dslabel = ds.label;
var nobs = ds.n;
var upd = ds.updated;
var ndim = ds.length;
var dimid = ds.id;
var sex = ds.Dimension( "sex" );
Let’s analyze dimension “sex”.
Selected by ID.
var dslabel = ds.label;
var nobs = ds.n;
var upd = ds.updated;
var ndim = ds.length;
var dimid = ds.id;
var sex = ds.Dimension( "sex" );
var sexsize = sex.length;
var sexid = sex.id;
sex.length is not what it seems: it’s just
the number of categories of dimension“sex”.
sex.length → 3
sex.id → ["T", "M", "F"]
var dslabel = ds.label;
var nobs = ds.n;
var upd = ds.updated;
var ndim = ds.length;
var dimid = ds.id;
var sex = ds.Dimension( "sex" );
var sexsize = sex.length;
var sexid = sex.id;
var sexlabel = sex.label;
As you can see, properties length, id and label
are everywhere.
sex.label → "sex"
var dslabel = ds.label;
var nobs = ds.n;
var upd = ds.updated;
var ndim = ds.length;
var dimid = ds.id;
var sex = ds.Dimension( "sex" );
var sexsize = sex.length;
var sexid = sex.id;
var sexlabel = sex.label;
var sexrole = sex.role;
sex is considered a classification variable because
the provider didn’t attach any special role to it.
sex.role → classification
var yearrole = ds.Dimension( "year" ).role;
var countryrole = ds.Dimension( "country" ).role;
Special roles are time, geo and metric.
ds.Dimension( "year" ).role → "time"
ds.Dimension( "country" ).role → "geo"
var yearrole = ds.Dimension( "year" ).role;
var countryrole = ds.Dimension( "country" ).role;
var timedims = ds.role.time;
var geodims = ds.role.geo;
Likewise, you can ask the other way around.
Get dimensions with role time and role geo.
ds.role.time → ["year"]
ds.role.geo → ["country"]
var sexlabel2 = sex.Category( 2 ).label;
var sexunit2 = sex.Category( 2 ).unit;
var sexcoord2 = sex.Category( 2 ).coordinates;
Get information about a particular sex category.
By index.
sex.Category( 2 ).label → "female"
.unit, .coordinates (only if role metric / geo) → null
var sexlabel2 = sex.Category( "F" ).label;
var sexunit2 = sex.Category( "F" ).unit;
var sexcoord2 = sex.Category( "F" ).coordinates;
Get information about a particular sex category.
By ID.
sex.Category( "F" ).label → "female"
.unit, .coordinates (only if role metric / geo) → null
var dimarray = ds.Dimension( );
var sexarray = sex.Category( );
All methods can be called without arguments.
They will return an array of results.
var dimarray = ds.Dimension( );
var sexarray = sex.Category( );
var malelabel = ds
.Dimension( )[4]
.Category( )[1]
.label;
Use responsibly!
Always minimize calling methods
without arguments.
// sex (5th dimension)
// male (2nd category)
var dimarray = ds.Dimension( );
var sexarray = sex.Category( );
var malelabel = ds
.Dimension( 4 )
.Category( 1 )
.label;
Simpler.
Still, you should minimize calling
the same method with the same argument
several times.
// sex (5th dimension)
// male (2nd category)
var dimarray = ds.Dimension( );
var sexarray = sex.Category( );
var malelabel =
sex
.Category( 1 )
.label;
If you must, store the result in a variable.
// sex (5th dimension)
// male (2nd category)
the
JSON-stat
Javascript
Toolkit
It offers methods
to easily traverse
the JSON-stat
tree:
Dataset
Dimension
Category
Data
var cell44 = ds.Data( 44 ).value;
var cell44 = ds.Data( [0,0,7,0,2] ).value;
Get the value in cell 44.
By value index and by dimensions’ indexes.
ds.Data( 44 ).value → 1202.8
ds.Data( [0,0,7,0,2] ).value → 1202.8
var cell44 = ds.Data( 44 ).value;
var cell44 = ds.Data( [0,0,7,0,2] ).value;
var cell44 = ds.Data( {
country: "CA",
year : "2012",
concept : "POP",
age: "34",
sex: "F"
} ).value;
Get the value in cell 44.
By dimension/category ID.
ds.Data( {…} ).value → 1202.8
var cell44 = ds.Data( 44 ).value;
var cell44 = ds.Data( [0,0,7,0,2] ).value;
var cell44 = ds.Data( {
country: "CA",
year : "2012",
concept : "POP",
age: "34",
sex: "F"
} ).value;
Single category dimensions are not required.
By dimension/category ID.
ds.Data( {…} ).value → 1202.8
var cell44 = ds.Data( 44 ).status;
var cell44 = ds.Data( [0,0,7,0,2] ).status;
var cell44 = ds.Data( {
country: "CA",
year : "2012",
concept : "POP",
age: "34",
sex: "F"
} ).status;
Get cell status, if available.
By dimension/category ID.
ds.Data( {…} ).status → "a"
var pop34 = ds.Data( {
country: "CA",
year : "2012",
concept : "POP",
age: "34",
sex: "F"
} );
By removing one (and only one) required
dimension, you get an array of results (slice).
(In the example, population of age 30-34
by sex in Canada in 2012.)
var data = ds.Data( );
Get an array with information for every cell.
(“Information” currently means value and status.)
var data = ds.Data( );
// It allows you to rebuild the value array like this:
var value = ds.Data( ).map(
function( e ){
return e.value;
}
);
// But you can directly access the original value and status
// like this:
var value = ds.value;
var status = ds.status;
J.Dataset( )
.Dimension( )
.Category( )
.Data( )
Chainable traversing methods
J.Dataset( )
.toTable( )
Chainable transformation methods
J.Dataset( )
.Dimension( )
.Category( )
.Data( )
Chainable traversing methods
J.Dataset( )
.toTable( )
Chainable transformation methods
Get sections of the dataset.
Get data and main metadata
in tabular form.
J.Dataset( )
.toTable( )
Chainable transformation methods
Get data and main metadata
in tabular form.
Useful to export the dataset content
to other table-based structures
var tbl = ds.toTable( { type : "arrobj" } );
[
{
age : "Total",
concept : "Persons (thousands)",
country : "Canada",
sex : "Total",
value : 34880.5,
year : "2012"
},
{
age : "Total",
concept : "Persons (thousands)",
country : "Canada",
sex : "Male",
value : 17309.1,
year : "2012"
},
…
]
Get an array of objects describing every cell.
var tbl = ds.toTable( { type : "arrobj", status : true } );
[
{
age : "Total",
concept : "Persons (thousands)",
country : "Canada",
sex : "Total",
value : 34880.5, status : "a",
year : "2012"
},
{
age : "Total",
concept : "Persons (thousands)",
country : "Canada",
sex : "Male",
value : 17309.1, status : "a",
year : "2012"
},
…
]
It can include status information.
var tbl = ds.toTable( { type : "arrobj", content : "id" } );
[
{
age : "T",
concept : "POP",
country : "CA",
sex : "T",
value : 34880.5,
year : "2012"
},
{
age : "T",
concept : "POP",
country : "CA",
sex : "M",
value : 17309.1,
year : "2012"
},
…
]
It can use categories’ IDs instead of labels.
var tbl = ds.toTable(
{
type : "arrobj",
content : "id",
function ( d, i ){
if ( d.sex === "F" && d.concept === "POP" ){
return { age : d.age, population : d.value*1000 };
}
}
}
);
// Get only slice females, persons (in thousands), transform
// thousands into persons and keep age and population only.
It can be post-processed with a callback function.
var tbl = ds.toTable( { type : "object" } );
{
cols : [
{
id : "country",
label : "Country",
type : "string",
},
{
id : "year",
label : "Year",
type : "string",
},
...
],
rows : [
...
]
}
Get an object of arrays (Google DataTable format).
var tbl = ds.toTable( { type : "array" } );
[
[
"Country",
"Year",
"Age group",
"Population and %",
"Sex",
"Value"
],
[
"Canada",
"2012",
"Total",
"Persons (thousands)",
"Total",
34880.5
],
...
]
Get an array of arrays (CSV-like format).
These are just
the main features of
the
JSON-stat
Javascript
Toolkit
json-stat.com
JJT is also available
on the server as
a Node.js module.
npm install jsonstat
https://www.npmjs.com/package/jsonstat
Built on top of JJT
the
JSON-stat
Javascript
Utilities
Suite
Built on top of JJT
the
JSON-stat
Javascript
Utilities
Suite
High level utilities
tbrowser: interactive,
pivotal table
datalist: unidimensional
table
fromTable: import from
JSON tabular formats
fromCSV/toCSV:
import/export from/to
CSV
thank you
all pictures from
Blocks picture in slide 1: Soma, by Dru! (CC BY-NC)
Atomium in slide 2: Fighting Gravity –
Atomium, Brussels, by Jan Faborsky
(CC BY-NC-ND)
Sculture in slide 3: Cubes, by Alex
[Fino] LA (CC BY-SA)
Egg in slide 50: Egg, by Auntie P
(CC BY-NC-SA)

More Related Content

PDF
JSON-stat, a simple light standard for all kinds of data disseminators
PPT
JDBC
PPTX
Pertemuan 2_Array.pptx
PDF
Mementopython3 english
PPTX
18. Java associative arrays
PPTX
Intro To Mongo Db
PDF
Kiss PageObjects [01-2017]
PDF
MongodB Internals
JSON-stat, a simple light standard for all kinds of data disseminators
JDBC
Pertemuan 2_Array.pptx
Mementopython3 english
18. Java associative arrays
Intro To Mongo Db
Kiss PageObjects [01-2017]
MongodB Internals

What's hot (14)

PPTX
20.4 Java interfaces and abstraction
PDF
Java 8, Streams & Collectors, patterns, performances and parallelization
PPT
C# Variables and Operators
PPT
JavaScript
PPTX
Java Foundations: Data Types and Type Conversion
PDF
Практикум Web программирование
PDF
QA Fes 2016. Алексей Виноградов. Page Objects: лучше проще, да лучшe
PDF
How queries work with sharding
PPTX
Drools Ecosystem
PPT
Introduction to mongodb
PPT
PDBC
PDF
Chapitre 2: String en Java
PPT
леся українка, 6 клас
PPTX
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
20.4 Java interfaces and abstraction
Java 8, Streams & Collectors, patterns, performances and parallelization
C# Variables and Operators
JavaScript
Java Foundations: Data Types and Type Conversion
Практикум Web программирование
QA Fes 2016. Алексей Виноградов. Page Objects: лучше проще, да лучшe
How queries work with sharding
Drools Ecosystem
Introduction to mongodb
PDBC
Chapitre 2: String en Java
леся українка, 6 клас
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Ad

Similar to JSON-stat & JS: the JSON-stat Javascript Toolkit (20)

PDF
Working with the Web: 
Decoding JSON
PDF
Json at work overview and ecosystem-v2.0
PDF
More expressive types for spark with frameless
PPT
Advanced Json
PDF
Intro to MongoDB and datamodeling
PDF
DataMapper @ RubyEnRails2009
KEY
Indexing with MongoDB
PPT
jQuery Datatables With MongDb
PDF
Automatically Spotting Cross-language Relations
PDF
Http4s, Doobie and Circe: The Functional Web Stack
PDF
Casting for not so strange actors
PPTX
Webinar: Exploring the Aggregation Framework
KEY
Data Representation - Day 2
PPT
Schema design short
PPTX
Webinar: Strongly Typed Languages and Flexible Schemas
PDF
JSON and Swift, Still A Better Love Story Than Twilight
PDF
Persisting Data on SQLite using Room
PDF
An Introduction to Scala (2014)
PDF
Consuming Nordic Statbank data with JSON-stat
PDF
Strongly Typed Languages and Flexible Schemas
Working with the Web: 
Decoding JSON
Json at work overview and ecosystem-v2.0
More expressive types for spark with frameless
Advanced Json
Intro to MongoDB and datamodeling
DataMapper @ RubyEnRails2009
Indexing with MongoDB
jQuery Datatables With MongDb
Automatically Spotting Cross-language Relations
Http4s, Doobie and Circe: The Functional Web Stack
Casting for not so strange actors
Webinar: Exploring the Aggregation Framework
Data Representation - Day 2
Schema design short
Webinar: Strongly Typed Languages and Flexible Schemas
JSON and Swift, Still A Better Love Story Than Twilight
Persisting Data on SQLite using Room
An Introduction to Scala (2014)
Consuming Nordic Statbank data with JSON-stat
Strongly Typed Languages and Flexible Schemas
Ad

More from Xavier Badosa (20)

PDF
Putting Data in Cells
PDF
JSON-stat in the Sea of Standards
PDF
The Trouble with Tables
PDF
StatisticalTable, a JSON-stat-based vocabulary
PDF
Decoupling Official Statistics
PDF
JSON-stat in the session "The future of standards in statistics", United Nati...
PDF
Data Dissemination through Data Visualization
PDF
Reutilización de datos gracias a la visualización de datos
PDF
Idescat Visual: Gràfics i mapes
PDF
Gov APIs: The Notorious Case of Official Statistics
PDF
Periodisme de dades i oficines estadístiques
PPTX
Difusió estadísTICa oficial
PPTX
Links and Widgets: the Fabric of the Web
PPTX
La difusión estadística y la apertura de datos: un viaje de ida y vuelta
PPTX
Standards for statistical data dissemination: a wish list
PPTX
What's our business? Statistics as platform
PPTX
Idescat on the Google Public Data Explorer
PPTX
El Idescat en Google Public Data Explorer
PPTX
Los widgets del Idescat: una aplicación de las APIs
PPTX
Anatomía de las APIs del Idescat
Putting Data in Cells
JSON-stat in the Sea of Standards
The Trouble with Tables
StatisticalTable, a JSON-stat-based vocabulary
Decoupling Official Statistics
JSON-stat in the session "The future of standards in statistics", United Nati...
Data Dissemination through Data Visualization
Reutilización de datos gracias a la visualización de datos
Idescat Visual: Gràfics i mapes
Gov APIs: The Notorious Case of Official Statistics
Periodisme de dades i oficines estadístiques
Difusió estadísTICa oficial
Links and Widgets: the Fabric of the Web
La difusión estadística y la apertura de datos: un viaje de ida y vuelta
Standards for statistical data dissemination: a wish list
What's our business? Statistics as platform
Idescat on the Google Public Data Explorer
El Idescat en Google Public Data Explorer
Los widgets del Idescat: una aplicación de las APIs
Anatomía de las APIs del Idescat

Recently uploaded (20)

PPTX
Introduction to machine learning and Linear Models
PDF
Fluorescence-microscope_Botany_detailed content
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPT
Reliability_Chapter_ presentation 1221.5784
PPTX
1_Introduction to advance data techniques.pptx
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
Market Analysis -202507- Wind-Solar+Hybrid+Street+Lights+for+the+North+Amer...
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
SAP 2 completion done . PRESENTATION.pptx
PPTX
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PPTX
STERILIZATION AND DISINFECTION-1.ppthhhbx
PDF
Introduction to the R Programming Language
PPTX
Introduction to Knowledge Engineering Part 1
Introduction to machine learning and Linear Models
Fluorescence-microscope_Botany_detailed content
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Clinical guidelines as a resource for EBP(1).pdf
Reliability_Chapter_ presentation 1221.5784
1_Introduction to advance data techniques.pptx
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Galatica Smart Energy Infrastructure Startup Pitch Deck
Market Analysis -202507- Wind-Solar+Hybrid+Street+Lights+for+the+North+Amer...
Business Ppt On Nestle.pptx huunnnhhgfvu
SAP 2 completion done . PRESENTATION.pptx
AI Strategy room jwfjksfksfjsjsjsjsjfsjfsj
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
STERILIZATION AND DISINFECTION-1.ppthhhbx
Introduction to the R Programming Language
Introduction to Knowledge Engineering Part 1

JSON-stat & JS: the JSON-stat Javascript Toolkit

  • 1. JSON-stat & JS the JSON-stat Javascript Toolkit Xavier Badosa @badosa https://xavierbadosa.com https://json-stat.org July, 2013 (updated to JSON-stat 2.0 in January, 2016)
  • 4. Introducing the JSON-stat Javascript Toolkit It’s a Javascript library that helps you dealing with JSON-stat responses.
  • 5. Introducing the JSON-stat Javascript Toolkit It offers methods to easily traverse the JSON-stat tree: Dataset Dimension Category Data
  • 7. Sample file the JSON-stat Javascript Toolkit This URL returns a JSON-stat dataset document. (Collections can contain several datasets.) json-stat.org/samples/canada.json
  • 8. var ds = JSONstat( "http://json-stat.org/samples/canada.json" ); if ( ds.length > 0 ) { … } Retrieve a JSON-stat document. Check the number of elements. If zero, the service didn’t return a valid JSON-stat response. Sync
  • 9. JSONstat( "http://json-stat.org/samples/canada.json", function () { if ( this.length > 0 ) { … } } ); Retrieve a JSON-stat document. Check the number of elements. If zero, the service didn’t return a valid JSON-stat response. Async
  • 10. $.getJSON( "http://json-stat.org/samples/canada.json", function ( obj ) { var ds = JSONstat( obj ); if ( ds.length > 0 ) { … } } ); You can also retrieve a JSON-stat document with your usual bullet-proof framework and use JSONstat() for what is good for: dealing with the resulting object.
  • 11. var ds = JSONstat( "http://json-stat.org/samples/canada.json" ); var cl = ds.class; It contains a dataset (a cube). ds.class → "dataset"
  • 12. var ds = JSONstat( "http://json-stat.org/samples/canada.json" ); var cl = ds.class; (Because it’s a dataset response you don’t need to use the Dataset() method.) ds === ds.Dataset( 0 ) → true
  • 13. var dslabel = ds.label; Get the dataset label. ds.label → "Population by sex and age group. Canada. 2012"
  • 14. var dslabel = ds.label; var nobs = ds.n; var upd = ds.updated; // new Date(upd) to convert into date Get the number of data in the dataset and the update information. ds.n → 120 ds.updated → "2012-09-27"
  • 15. var dslabel = ds.label; var nobs = ds.n; var upd = ds.updated; var ndim = ds.length; var dimid = ds.id; Get the number of dimensions and the dimensions’ IDs. ds.length → 5 ds.id → ["country", "year", "age", "concept", "sex"]
  • 16. var dslabel = ds.label; var nobs = ds.n; var upd = ds.updated; var ndim = ds.length; var dimid = ds.id; var sex = ds.Dimension( 4 ); Let’s analyze dimension “sex”. Selected by index.
  • 17. var dslabel = ds.label; var nobs = ds.n; var upd = ds.updated; var ndim = ds.length; var dimid = ds.id; var sex = ds.Dimension( "sex" ); Let’s analyze dimension “sex”. Selected by ID.
  • 18. var dslabel = ds.label; var nobs = ds.n; var upd = ds.updated; var ndim = ds.length; var dimid = ds.id; var sex = ds.Dimension( "sex" ); var sexsize = sex.length; var sexid = sex.id; sex.length is not what it seems: it’s just the number of categories of dimension“sex”. sex.length → 3 sex.id → ["T", "M", "F"]
  • 19. var dslabel = ds.label; var nobs = ds.n; var upd = ds.updated; var ndim = ds.length; var dimid = ds.id; var sex = ds.Dimension( "sex" ); var sexsize = sex.length; var sexid = sex.id; var sexlabel = sex.label; As you can see, properties length, id and label are everywhere. sex.label → "sex"
  • 20. var dslabel = ds.label; var nobs = ds.n; var upd = ds.updated; var ndim = ds.length; var dimid = ds.id; var sex = ds.Dimension( "sex" ); var sexsize = sex.length; var sexid = sex.id; var sexlabel = sex.label; var sexrole = sex.role; sex is considered a classification variable because the provider didn’t attach any special role to it. sex.role → classification
  • 21. var yearrole = ds.Dimension( "year" ).role; var countryrole = ds.Dimension( "country" ).role; Special roles are time, geo and metric. ds.Dimension( "year" ).role → "time" ds.Dimension( "country" ).role → "geo"
  • 22. var yearrole = ds.Dimension( "year" ).role; var countryrole = ds.Dimension( "country" ).role; var timedims = ds.role.time; var geodims = ds.role.geo; Likewise, you can ask the other way around. Get dimensions with role time and role geo. ds.role.time → ["year"] ds.role.geo → ["country"]
  • 23. var sexlabel2 = sex.Category( 2 ).label; var sexunit2 = sex.Category( 2 ).unit; var sexcoord2 = sex.Category( 2 ).coordinates; Get information about a particular sex category. By index. sex.Category( 2 ).label → "female" .unit, .coordinates (only if role metric / geo) → null
  • 24. var sexlabel2 = sex.Category( "F" ).label; var sexunit2 = sex.Category( "F" ).unit; var sexcoord2 = sex.Category( "F" ).coordinates; Get information about a particular sex category. By ID. sex.Category( "F" ).label → "female" .unit, .coordinates (only if role metric / geo) → null
  • 25. var dimarray = ds.Dimension( ); var sexarray = sex.Category( ); All methods can be called without arguments. They will return an array of results.
  • 26. var dimarray = ds.Dimension( ); var sexarray = sex.Category( ); var malelabel = ds .Dimension( )[4] .Category( )[1] .label; Use responsibly! Always minimize calling methods without arguments. // sex (5th dimension) // male (2nd category)
  • 27. var dimarray = ds.Dimension( ); var sexarray = sex.Category( ); var malelabel = ds .Dimension( 4 ) .Category( 1 ) .label; Simpler. Still, you should minimize calling the same method with the same argument several times. // sex (5th dimension) // male (2nd category)
  • 28. var dimarray = ds.Dimension( ); var sexarray = sex.Category( ); var malelabel = sex .Category( 1 ) .label; If you must, store the result in a variable. // sex (5th dimension) // male (2nd category)
  • 29. the JSON-stat Javascript Toolkit It offers methods to easily traverse the JSON-stat tree: Dataset Dimension Category Data
  • 30. var cell44 = ds.Data( 44 ).value; var cell44 = ds.Data( [0,0,7,0,2] ).value; Get the value in cell 44. By value index and by dimensions’ indexes. ds.Data( 44 ).value → 1202.8 ds.Data( [0,0,7,0,2] ).value → 1202.8
  • 31. var cell44 = ds.Data( 44 ).value; var cell44 = ds.Data( [0,0,7,0,2] ).value; var cell44 = ds.Data( { country: "CA", year : "2012", concept : "POP", age: "34", sex: "F" } ).value; Get the value in cell 44. By dimension/category ID. ds.Data( {…} ).value → 1202.8
  • 32. var cell44 = ds.Data( 44 ).value; var cell44 = ds.Data( [0,0,7,0,2] ).value; var cell44 = ds.Data( { country: "CA", year : "2012", concept : "POP", age: "34", sex: "F" } ).value; Single category dimensions are not required. By dimension/category ID. ds.Data( {…} ).value → 1202.8
  • 33. var cell44 = ds.Data( 44 ).status; var cell44 = ds.Data( [0,0,7,0,2] ).status; var cell44 = ds.Data( { country: "CA", year : "2012", concept : "POP", age: "34", sex: "F" } ).status; Get cell status, if available. By dimension/category ID. ds.Data( {…} ).status → "a"
  • 34. var pop34 = ds.Data( { country: "CA", year : "2012", concept : "POP", age: "34", sex: "F" } ); By removing one (and only one) required dimension, you get an array of results (slice). (In the example, population of age 30-34 by sex in Canada in 2012.)
  • 35. var data = ds.Data( ); Get an array with information for every cell. (“Information” currently means value and status.)
  • 36. var data = ds.Data( ); // It allows you to rebuild the value array like this: var value = ds.Data( ).map( function( e ){ return e.value; } ); // But you can directly access the original value and status // like this: var value = ds.value; var status = ds.status;
  • 37. J.Dataset( ) .Dimension( ) .Category( ) .Data( ) Chainable traversing methods J.Dataset( ) .toTable( ) Chainable transformation methods
  • 38. J.Dataset( ) .Dimension( ) .Category( ) .Data( ) Chainable traversing methods J.Dataset( ) .toTable( ) Chainable transformation methods Get sections of the dataset. Get data and main metadata in tabular form.
  • 39. J.Dataset( ) .toTable( ) Chainable transformation methods Get data and main metadata in tabular form. Useful to export the dataset content to other table-based structures
  • 40. var tbl = ds.toTable( { type : "arrobj" } ); [ { age : "Total", concept : "Persons (thousands)", country : "Canada", sex : "Total", value : 34880.5, year : "2012" }, { age : "Total", concept : "Persons (thousands)", country : "Canada", sex : "Male", value : 17309.1, year : "2012" }, … ] Get an array of objects describing every cell.
  • 41. var tbl = ds.toTable( { type : "arrobj", status : true } ); [ { age : "Total", concept : "Persons (thousands)", country : "Canada", sex : "Total", value : 34880.5, status : "a", year : "2012" }, { age : "Total", concept : "Persons (thousands)", country : "Canada", sex : "Male", value : 17309.1, status : "a", year : "2012" }, … ] It can include status information.
  • 42. var tbl = ds.toTable( { type : "arrobj", content : "id" } ); [ { age : "T", concept : "POP", country : "CA", sex : "T", value : 34880.5, year : "2012" }, { age : "T", concept : "POP", country : "CA", sex : "M", value : 17309.1, year : "2012" }, … ] It can use categories’ IDs instead of labels.
  • 43. var tbl = ds.toTable( { type : "arrobj", content : "id", function ( d, i ){ if ( d.sex === "F" && d.concept === "POP" ){ return { age : d.age, population : d.value*1000 }; } } } ); // Get only slice females, persons (in thousands), transform // thousands into persons and keep age and population only. It can be post-processed with a callback function.
  • 44. var tbl = ds.toTable( { type : "object" } ); { cols : [ { id : "country", label : "Country", type : "string", }, { id : "year", label : "Year", type : "string", }, ... ], rows : [ ... ] } Get an object of arrays (Google DataTable format).
  • 45. var tbl = ds.toTable( { type : "array" } ); [ [ "Country", "Year", "Age group", "Population and %", "Sex", "Value" ], [ "Canada", "2012", "Total", "Persons (thousands)", "Total", 34880.5 ], ... ] Get an array of arrays (CSV-like format).
  • 46. These are just the main features of the JSON-stat Javascript Toolkit json-stat.com
  • 47. JJT is also available on the server as a Node.js module. npm install jsonstat https://www.npmjs.com/package/jsonstat
  • 48. Built on top of JJT the JSON-stat Javascript Utilities Suite
  • 49. Built on top of JJT the JSON-stat Javascript Utilities Suite High level utilities tbrowser: interactive, pivotal table datalist: unidimensional table fromTable: import from JSON tabular formats fromCSV/toCSV: import/export from/to CSV
  • 51. all pictures from Blocks picture in slide 1: Soma, by Dru! (CC BY-NC) Atomium in slide 2: Fighting Gravity – Atomium, Brussels, by Jan Faborsky (CC BY-NC-ND) Sculture in slide 3: Cubes, by Alex [Fino] LA (CC BY-SA) Egg in slide 50: Egg, by Auntie P (CC BY-NC-SA)