SlideShare uma empresa Scribd logo
1 de 51
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)

Mais conteúdo relacionado

Mais procurados

What is self-sovereign identity (SSI)?
What is self-sovereign identity (SSI)?What is self-sovereign identity (SSI)?
What is self-sovereign identity (SSI)?Evernym
 
Masterclass on the DID Universal Resolver
Masterclass on the DID Universal ResolverMasterclass on the DID Universal Resolver
Masterclass on the DID Universal ResolverMarkus Sabadello
 
Windows Server 2012 Exam Paper 70-411 PDF
Windows Server 2012 Exam Paper 70-411 PDFWindows Server 2012 Exam Paper 70-411 PDF
Windows Server 2012 Exam Paper 70-411 PDFKesavan Munuswamy
 
ORCID for researchers: What, why, how?
ORCID for researchers: What, why, how?ORCID for researchers: What, why, how?
ORCID for researchers: What, why, how?ORCID, Inc
 
Back to Basics 1: Thinking in documents
Back to Basics 1: Thinking in documentsBack to Basics 1: Thinking in documents
Back to Basics 1: Thinking in documentsMongoDB
 
DSpace standard Data model and DSpace-CRIS
DSpace standard Data model and DSpace-CRISDSpace standard Data model and DSpace-CRIS
DSpace standard Data model and DSpace-CRISAndrea Bollini
 
Social Awareness on Smart Cities
Social Awareness on Smart CitiesSocial Awareness on Smart Cities
Social Awareness on Smart Citiesnitin bisht
 
DSpace implementation of the COAR Notify Project - status update
DSpace implementation of the COAR Notify Project - status updateDSpace implementation of the COAR Notify Project - status update
DSpace implementation of the COAR Notify Project - status update4Science
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesLewis Lin 🦊
 
MDG-M einfach einführen
MDG-M einfach einführenMDG-M einfach einführen
MDG-M einfach einführenIBsolution GmbH
 

Mais procurados (11)

What is self-sovereign identity (SSI)?
What is self-sovereign identity (SSI)?What is self-sovereign identity (SSI)?
What is self-sovereign identity (SSI)?
 
Masterclass on the DID Universal Resolver
Masterclass on the DID Universal ResolverMasterclass on the DID Universal Resolver
Masterclass on the DID Universal Resolver
 
Windows Server 2012 Exam Paper 70-411 PDF
Windows Server 2012 Exam Paper 70-411 PDFWindows Server 2012 Exam Paper 70-411 PDF
Windows Server 2012 Exam Paper 70-411 PDF
 
ORCID for researchers: What, why, how?
ORCID for researchers: What, why, how?ORCID for researchers: What, why, how?
ORCID for researchers: What, why, how?
 
Back to Basics 1: Thinking in documents
Back to Basics 1: Thinking in documentsBack to Basics 1: Thinking in documents
Back to Basics 1: Thinking in documents
 
DSpace standard Data model and DSpace-CRIS
DSpace standard Data model and DSpace-CRISDSpace standard Data model and DSpace-CRIS
DSpace standard Data model and DSpace-CRIS
 
itsme Digital ID turns 3
itsme Digital ID turns 3itsme Digital ID turns 3
itsme Digital ID turns 3
 
Social Awareness on Smart Cities
Social Awareness on Smart CitiesSocial Awareness on Smart Cities
Social Awareness on Smart Cities
 
DSpace implementation of the COAR Notify Project - status update
DSpace implementation of the COAR Notify Project - status updateDSpace implementation of the COAR Notify Project - status update
DSpace implementation of the COAR Notify Project - status update
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
MDG-M einfach einführen
MDG-M einfach einführenMDG-M einfach einführen
MDG-M einfach einführen
 

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

Working with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSONWorking with the Web: 
Decoding JSON
Working with the Web: 
Decoding JSONSV.CO
 
More expressive types for spark with frameless
More expressive types for spark with framelessMore expressive types for spark with frameless
More expressive types for spark with framelessMiguel Pérez Pasalodos
 
Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling Intro to MongoDB and datamodeling
Intro to MongoDB and datamodeling rogerbodamer
 
DataMapper @ RubyEnRails2009
DataMapper @ RubyEnRails2009DataMapper @ RubyEnRails2009
DataMapper @ RubyEnRails2009Dirkjan Bussink
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDBlehresman
 
jQuery Datatables With MongDb
jQuery Datatables With MongDbjQuery Datatables With MongDb
jQuery Datatables With MongDbsliimohara
 
Automatically Spotting Cross-language Relations
Automatically Spotting Cross-language RelationsAutomatically Spotting Cross-language Relations
Automatically Spotting Cross-language RelationsFederico Tomassetti
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackGaryCoady
 
Casting for not so strange actors
Casting for not so strange actorsCasting for not so strange actors
Casting for not so strange actorszucaritask
 
Webinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkWebinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkMongoDB
 
Data Representation - Day 2
Data Representation - Day 2Data Representation - Day 2
Data Representation - Day 2blprnt
 
Schema design short
Schema design shortSchema design short
Schema design shortMongoDB
 
Webinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible SchemasWebinar: Strongly Typed Languages and Flexible Schemas
Webinar: Strongly Typed Languages and Flexible SchemasMongoDB
 
JSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightJSON and Swift, Still A Better Love Story Than Twilight
JSON and Swift, Still A Better Love Story Than TwilightDonny Wals
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using RoomNelson Glauber Leal
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)William Narmontas
 
Consuming Nordic Statbank data with JSON-stat
Consuming Nordic Statbank data with JSON-statConsuming Nordic Statbank data with JSON-stat
Consuming Nordic Statbank data with JSON-statXavier Badosa
 
Strongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible SchemasStrongly Typed Languages and Flexible Schemas
Strongly Typed Languages and Flexible SchemasNorberto Leite
 

Semelhante a JSON-stat & JS: the JSON-stat Javascript Toolkit (20)

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

Mais de Xavier Badosa

Putting Data in Cells
Putting Data in CellsPutting Data in Cells
Putting Data in CellsXavier Badosa
 
JSON-stat in the Sea of Standards
JSON-stat in the Sea of StandardsJSON-stat in the Sea of Standards
JSON-stat in the Sea of StandardsXavier Badosa
 
The Trouble with Tables
The Trouble with TablesThe Trouble with Tables
The Trouble with TablesXavier Badosa
 
StatisticalTable, a JSON-stat-based vocabulary
StatisticalTable, a JSON-stat-based vocabularyStatisticalTable, a JSON-stat-based vocabulary
StatisticalTable, a JSON-stat-based vocabularyXavier Badosa
 
Decoupling Official Statistics
Decoupling Official StatisticsDecoupling Official Statistics
Decoupling Official StatisticsXavier Badosa
 
JSON-stat in the session "The future of standards in statistics", United Nati...
JSON-stat in the session "The future of standards in statistics", United Nati...JSON-stat in the session "The future of standards in statistics", United Nati...
JSON-stat in the session "The future of standards in statistics", United Nati...Xavier Badosa
 
Data Dissemination through Data Visualization
Data Dissemination through Data VisualizationData Dissemination through Data Visualization
Data Dissemination through Data VisualizationXavier Badosa
 
Reutilización de datos gracias a la visualización de datos
Reutilización de datos gracias a la visualización de datosReutilización de datos gracias a la visualización de datos
Reutilización de datos gracias a la visualización de datosXavier Badosa
 
Idescat Visual: Gràfics i mapes
Idescat Visual: Gràfics i mapesIdescat Visual: Gràfics i mapes
Idescat Visual: Gràfics i mapesXavier Badosa
 
Gov APIs: The Notorious Case of Official Statistics
Gov APIs: The Notorious Case of Official StatisticsGov APIs: The Notorious Case of Official Statistics
Gov APIs: The Notorious Case of Official StatisticsXavier Badosa
 
Periodisme de dades i oficines estadístiques
Periodisme de dades i oficines estadístiquesPeriodisme de dades i oficines estadístiques
Periodisme de dades i oficines estadístiquesXavier Badosa
 
Difusió estadísTICa oficial
Difusió estadísTICa oficialDifusió estadísTICa oficial
Difusió estadísTICa oficialXavier Badosa
 
Links and Widgets: the Fabric of the Web
Links and Widgets: the Fabric of the WebLinks and Widgets: the Fabric of the Web
Links and Widgets: the Fabric of the WebXavier Badosa
 
La difusión estadística y la apertura de datos: un viaje de ida y vuelta
La difusión estadística y la apertura de datos: un viaje de ida y vueltaLa difusión estadística y la apertura de datos: un viaje de ida y vuelta
La difusión estadística y la apertura de datos: un viaje de ida y vueltaXavier Badosa
 
Standards for statistical data dissemination: a wish list
Standards for statistical data dissemination: a wish listStandards for statistical data dissemination: a wish list
Standards for statistical data dissemination: a wish listXavier Badosa
 
What's our business? Statistics as platform
What's our business? Statistics as platformWhat's our business? Statistics as platform
What's our business? Statistics as platformXavier Badosa
 
Idescat on the Google Public Data Explorer
Idescat on the Google Public Data ExplorerIdescat on the Google Public Data Explorer
Idescat on the Google Public Data ExplorerXavier Badosa
 
El Idescat en Google Public Data Explorer
El Idescat en Google Public Data ExplorerEl Idescat en Google Public Data Explorer
El Idescat en Google Public Data ExplorerXavier Badosa
 
Los widgets del Idescat: una aplicación de las APIs
Los widgets del Idescat: una aplicación de las APIsLos widgets del Idescat: una aplicación de las APIs
Los widgets del Idescat: una aplicación de las APIsXavier Badosa
 
Anatomía de las APIs del Idescat
Anatomía de las APIs del IdescatAnatomía de las APIs del Idescat
Anatomía de las APIs del IdescatXavier Badosa
 

Mais de Xavier Badosa (20)

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

Último

Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfBoston Institute of Analytics
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfchwongval
 
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Boston Institute of Analytics
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectBoston Institute of Analytics
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queensdataanalyticsqueen03
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Boston Institute of Analytics
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesTimothy Spann
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
Real-Time AI Streaming - AI Max Princeton
Real-Time AI  Streaming - AI Max PrincetonReal-Time AI  Streaming - AI Max Princeton
Real-Time AI Streaming - AI Max PrincetonTimothy Spann
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our WorldEduminds Learning
 
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...Amil Baba Dawood bangali
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024thyngster
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 

Último (20)

Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdf
 
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
Data Analysis Project : Targeting the Right Customers, Presentation on Bank M...
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis Project
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queens
 
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
Decoding the Heart: Student Presentation on Heart Attack Prediction with Data...
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming PipelinesConf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
Conf42-LLM_Adding Generative AI to Real-Time Streaming Pipelines
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
Real-Time AI Streaming - AI Max Princeton
Real-Time AI  Streaming - AI Max PrincetonReal-Time AI  Streaming - AI Max Princeton
Real-Time AI Streaming - AI Max Princeton
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our World
 
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 

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)