Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

API Reference

Xavier Badosa edited this pageNov 24, 2019 ·75 revisions

WikiAPI Reference

This is the documentation of JSON-stat Javascript Toolkit version 0. Version 1 has a slightly different API and is documentedelsewhere.

Methods

By type

By hierarchy

Public Properties

class,coordinates,error,extension,hierarchy,href,id,label,length,link,n,size,note,role,size,source,status,unit,updated,value,version


Reading

JSONstat()


Parent: none
Description: Creates ajsonstat instance from an external input in theJSON-stat format
Summary:object JSONstat (object orstring resp [,function callback] [,boolean instance] )

Parameters

resp (required)

It can be an object in the JSON-stat format or a string representing a URL.

varj=JSONstat({ ...});if(j.length){...}else{window.alert("Wrong response!");}});

Warning: Using a string representing a URL in this manner is deprecated and will be probably removed in version 1 (when JSONstat is expected to support XHR using promises).

When a URL is specified, JSONstat will try to connect to it to retrieve an object in theJSON-stat format. The JSONstat connection capabilities are not available in the modules versions (Node.js and ECMAScript) (Node.js already comes with a built-inhttp module and many third-party modules already try to simplify such task, likerequest orgot) and are limited to modern browsers. If you need to support very old browsers, use an object in the JSON-stat format instead of a URL string.

When the URL is absolute, JSONstat will attempt a cross-domain http request. This requiresCORS support on the provider’s server. To avoid possible connection issues in older browsers, use a relative URL whenever possible.

Ifresp is a string and nocallback is specified (deprecated), the connection will be synchronous.

varj=JSONstat("https://json-stat.org/samples/oecd.json");if(j.length){...}else{window.alert("Wrong response!");}

Ifresp is an object,callback andinstance are ignored.

callback

It is a function. Deprecated (it will be probably removed in version 1, when JSONstat is expected to support XHR using promises).

Whencallback is specified andresp is not an object, the connection is asynchronous.callback is executed after the connection has successfully finished and the resultingjsonstat instance is assigned to thethis keyword.

JSONstat("https://json-stat.org/samples/oecd.json",function(){if(this.length){...}else{window.alert("Wrong response!");}});
instance

This boolean parameter (introduced in version 0.10.2) is only available when acallback is specified (asynchronous connection) and alters the content of thethis keyword. By default (true), thethis keyword contains ajsonstat instance. Wheninstance isfalse and the connection successful, JSONstat() simply performs a GET XMLHttpRequest and converts the resulting JSON text into an object in the JSON-stat format but it does not perform the default last step: it does not process this object to build ajsonstat instance (the kind of object you need to apply the methods in this documentation, which means that, in a typical situation, you will need to run JSONstat() twice.

JSONstat("https://json-stat.org/samples/oecd.json",function(){varlabel=JSONstat(this).label;},false);

This parameter may be useful in scenarios where cloning ajsonstat instance is necessary.

JSONstat("https://json-stat.org/samples/oecd.json",function(){varorig=JSONstat(this),copy=JSONstat(JSON.parse(JSON.stringify(this)));//Now you can safely manipulate the copy object://the orig object will remain unaffected},false);

Return Value

It returns ajsonstat instance. Whencallback is specified, thejsonstat instance returned by JSONstat will be empty: the actual instance (or a JSON-stat object ifinstance isfalse) will only be accessible inside the callback function, in thethis keyword.

The public properties of thejsonstat instance depend on the value of theclass property.

Common properties:class,length,id

Additional properties whenclass is "collection":label,updated,source,note,href,link,extension

Additional properties whenclass is "bundle":error

Additional properties whenclass is "dataset":label,n,size,value,status,updated,source,role,note,href,link,extension

Traversing

Dataset()


Parent:JSONstat
Description: Gets dataset information from ajsonstat ("bundle", "collection", "dataset") instance
Summary:object orarray Dataset ( [integer orstring dsid] )

Parameters

dsid

It can be a positive integer (access by index in the datasetsid array) or a string (access by ID).

Return Value

When a validdsid is specified, it returns ajsonstat instance. Ifdsid is not valid, anull is returned. Ifdsid is not specified, it will return an array ofjsonstat instances: one for each dataset.

JSONstat("https://json-stat.org/samples/oecd-canada.json",function(){if(this.class==="bundle"){vards1=this.Dataset(0);}});

The Dataset method can also be applied tojson-stat "collection" instances if they have some embedded dataset:

JSONstat("https://json-stat.org/samples/oecd-canada-col.json",function(){if(this.class==="collection"){vards1=this.Dataset(0);}});

For generalization's sake, it can also be applied tojson-stat "dataset" instances:

JSONstat("https://json-stat.org/samples/oecd.json",function(){if(this.class==="dataset"){window.alert(this===this.Dataset(0));//true}});

Dimension()


Parent:Dataset
Description: Gets dimension information from ajsonstat instance
Summary:object orarray Dimension ( [integer,string orobject dimid] [, boolean instance] )

Parameters

dimid

It can be a positive integer (access by index in the dimensionsid array) or a string (access by ID). If nodimid is specified, it will return information for every dimension.

JSONstat("https://json-stat.org/samples/oecd.json",function(){if(this.class==="dataset"){//Label of the first dimensionvarlabel1=this.Dimension(0).label;}});

It can also be an object in the form{ role :string }, wherestring is "time", "geo", "metric" or "classification". This syntax is used to filter dimensions with a particularrole.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Label of the first dimension with role "geo"vargeolabel1=this.Dimension({role :"geo"})[0].label;});
instance

This boolean parameter (introduced in version 0.12.2) is only available whendimid is specified and alters the return value. By default (true), the return value is ajsonstat instance (object), an array ofjsonstat instances ornull. When a validdimid is specified in combination withinstancetrue, the return value is an array of category labels for dimensiondimid or, whendimid is an object, an array of arrays (one for each selected dimension) of category labels.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Array of dimension "area" category labelsvararealabels=this.Dimension("area",false);//Same as: this.Dimension( "area" ).Category().map( function( e ){ return e.label; } )});

Return Value

When a validdimid is specified, it returns ajsonstat instance. Ifdimid is not valid, anull is returned. Ifdimid is not specified, it returns an array ofjsonstat instances: one for each dimension. Ifdimid is a valid object, it returns an array ofjsonstat instances: one for each dimension with the selectedrole.

Category()


Parent:Dimension
Description: Gets category information from ajsonstat instance
Public Properties:length,id,label,coordinates,unit,note
Summary:object orarray Category ( [integer orstring catid] )

Parameters

catid

It can be a positive integer (access by index in the categoriesid array) or a string (access by ID).

Return Value

When a validcatid is specified, it returns ajsonstat instance. Ifcatid is not valid, anull is returned. Ifcatid is not specified, it will return an array ofjsonstat instances: one for each category.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Label of category "AU" in dimension "area"varAUlabel=this.Dimension("area").Category("AU").label;//"Australia"});

Data()


Parent:Dataset
Description: Gets data information from ajsonstat instance
Public Properties:value,status
Summary:object,array,integer orstring Data ( [integer,array orobject dataid,boolean status] )

Parameters

dataid

It can be a positive integer (by index in thevalue array), an array (by dimensions indices) or an object (by dimensions IDs).

status

This boolean parameter (available since version 0.10.1) determines whether status information is retrieved or not (default istrue).

Return Value

If no parameter is specified, the result is an array ofvalue-status objects (one object per datum in the dataset).

Ifstatus is not specified or istrue, the return value can be avalue-status object (that is, an object with two properties:value andstatus), an array ofvalue-status objects ornull whendataid is not valid.

Ifdataid is an integer, the result is avalue-status object ifdataid is a valid index. Otherwise, anull is returned.

Ifdataid is an array, the result is avalue-status object ifdataid has the correct size (number of dimensions) and valid category indices. Otherwise, anull is returned.

Ifdataid is an object, a dimension is ignored if its ID or the ID of its category is invalid. If all dimensions/categories are correctly specified, the result is avalue-status object. Take into account that constant dimensions (that is, single category dimensions) are not required. Therefore, to get avalue-status object, you need to validly select a category for all the non-constant dimensions. If you do not validly select a category of a non-constant dimension (from now on, the free dimension), the return value will be an array ofvalue-status objects: one for each category in the free dimension (slice). Objects will be ordered in the free dimension category order. If there is more than one free dimension, anull will be returned.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Value of the first observationvardata0=this.Data(0).value;//Same as value with the first category in each dimensionvardata000=this.Data([0,0,0]).value;//Value with concept "UNR", area "GR" and year "2014"varunrGR2014=this.Data({"concept" :"UNR","area" :"GR","year" :"2014"}).value;});

Ifstatus isfalse,value-status objects will be replaced by simple values (usually a number; Data() returns whatever was included in the cell by the provider: number, string,null...). As a consequence, the return value will be a value, an array of values ornull whendataid is not valid.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Value of the first observationvardata0=this.Data(0,false);//Same as value with the first category in each dimensionvardata000=this.Data([0,0,0],false);//Value with concept "UNR", area "GR" and year "2014"varunrGR2014=this.Data({"concept" :"UNR","area" :"GR","year" :"2014"},false);});

Since version 0.10.3, it is possible to use an array of arrays instead of an object.

JSONstat("https://json-stat.org/samples/oecd.json",function(){varunrGR2014=this.Data([["concept","UNR"],["area","GR"],["year","2014"]]);//Same as { "concept" : "UNR", "area" : "GR", "year" : "2014" }});

Item()


Parent:JSONstat
Description: Gets item information from ajsonstat instance with class "collection"
Public Properties:class,href,label,extension
Summary:object orarray Item ( [integer orobject itemid] )

Parameters

itemid

It can be a positive integer (access to item information by index) or an object.

Whenitemid is an object, it must have a "class" property with a validclass value.

When the "class" property has "dataset" as its value, the object accepts the boolean property "embedded".

Return Value

When a validitemid is specified, it returns an item object (an object with the public properties of Item()). Ifitemid is an integer but out of range, anull is returned.

Ifitemid has a "class" property, it will return an array of item objects: those that meet the filter conditions; otherwise, anull is returned. When the "class" value is "dataset" and the boolean property "embedded" is specified, it will return an array with the items of class "dataset" that (true) are embedded or that (false) are not ("href", "label" and "extension" are included in the dataset item).

If the value of the "class" property is not a validclass value, an empty array is returned.

Whenitemid is not specified, it returns an array of item objects: one for each item.

JSONstat("https://json-stat.org/samples/collection.json",function(){//Get the label of the first item in the collectionvarlabel1=this.Item(0).label;});
JSONstat("https://json-stat.org/samples/collection.json",function(){//Get the number of items with class "dataset" in the collectionvardsn=this.Item({class :"dataset"}).length;});
JSONstat("https://json-stat.org/samples/collection.json",function(){//Get the number of embedded dataset in the collection (none)vardsn=this.Item({class :"dataset",embedded:true}).length;});

Transforming

toTable()


Parent:Dataset
Description: Converts information from ajsonstat instance into tabular form
Public Properties: —
Summary:object orarray toTable ( [object opts,function callback] )

Parameters

opts

It is an object with the following optional properties:

  • type: String (arrobj,object,array). Default value isarray. It determines the form of the return value.
  • status: Boolean. Default value isfalse. It determines whether the status of each value is included in the return value.
  • content: String (id,label). Default value islabel. It determines whether categories are identified in the return value by label or by ID.
  • field: String (id,label). Default value islabel. Only available whentype isobject orarray. It determines whether dimensions, value and status are identified in the return value by label or by ID.
  • vlabel: String. Default value isValue. Only available whentype isobject orarray. It determines the label of the value field.
  • slabel: String. Default value isStatus. Only available whentype isobject orarray andstatus istrue. It determines the label of the status field.
  • unit: Boolean. Default value isfalse. Only available whentype isarrobj. It determines whether unit information is included in the output. Whentrue, each object in the array includes aunit property with all the unit information attached to a value by the provider. It is assumed that there is only a dimension with rolemetric in the dataset (or at least only one with unit information). Available since version 0.12.3.
  • meta: Boolean. Default value isfalse. Only available whentype isarrobj. It determines the structure of the output. By default,arrobj returns data as an array of objects. Whenmeta istrue, metadata is included in the output, which takes the form of an object with two properties: "meta" and "data". The latter contains the same array of objects that is returned whenmeta isfalse. Available since version 0.13.0.
  • by: String. Only available whentype isarrobj. It must be the ID of an existing dimension; otherwise, it will be ignored. When a validby is specified, a property is created for each category of theby dimension (the "value" property is "transposed" by theby dimension). When a validby is specified,status andunit are ignored. Available since version 0.13.0.
  • bylabel: Boolean. Default isfalse. Only available whentype isarrobj. Whentrue, the categories of theby dimension are identified, once transposed, by their label instead of their ID. Available since version 0.13.3.
  • prefix: String. Only available whentype isarrobj. When values are transposed using theby option, category IDs end up being used as properties, side by side with dimension IDs. To avoid collision, a prefix can be specified to be added at the beginning of each new property created by the transposition. When no validby has been specified, theprefix property is ignored. Available since version 0.13.0.
  • drop: Array. Only available whentype isarrobj. This property is used to provide dimension IDs not to be included in the output. Invalid dimension IDs and non single category dimensions are ignored. When no validby is specified, thedrop property is ignored. Available since version 0.13.0.
  • comma: Boolean. Default value isfalse. Only available whentype isarrobj. Whentrue, values are represented as strings instead of numbers with comma as the decimal mark. Available since version 0.13.2.
JSONstat("https://json-stat.org/samples/canada.json",function(){//Column names (first row)//["country", "year", "age group", "concepts", "sex", "Value"]varcols=this.toTable({type :"array"})[0];//IDs instead of labels//["country", "year", "age", "concept", "sex", "value"]cols=this.toTable({type :"array",field :"id"})[0];//Labels including status//["country", "year", "age group", "concepts", "sex", "Status", "Value"]cols=this.toTable({type :"array",status :true})[0];//Same but naming status as "Metadata" and value as "Data"cols=this.toTable({type :"array",status :true,vlabel :"Data",slabel:"Metadata"})[0];//First data row//["Canada", "2012", "total", "population", "total", 34880.5]varrow1=this.toTable({type:"array"})[1];//Same including status//["Canada", "2012", "total", "population", "total", "a", 34880.5]row1=this.toTable({type:"array",status:true})[1];//Same but IDs instead of labels//["CA", "2012", "T", "POP", "T", "a", 34880.5]row1=this.toTable({type:"array",status:true,content:"id"})[1];});
callback

It is a function used to transform the return value.

Even though toTable can expose a table using different structures depending ontype, it always includes some sort of array for data.callback will be invoked for each element of the data array, passing two parameters: the element and its index. Thethis keyword incallback is the dataset information as ajsonstat instance.

JSONstat("https://json-stat.org/samples/canada.json",function(){//Discard data by age in the resulting tablethis.toTable({type :"arrobj"},function(d,i){if(d.age==="total"){returnd;}});});

Filters and transformations in thecallback must be expressed in terms of the form of the data array, which depends onopts. In the previous example, age is filtered using a category label (total) because this is the default value of thecontent option.

JSONstat("https://json-stat.org/samples/canada.json",function(){//Discard data by age in the resulting table.//Using categories ID instead of labels.this.toTable({type :"arrobj",content :"id"},function(d,i){if(d.age==="T"){returnd;}});});

Take into account that everytype returns a different form of data array.

JSONstat("https://json-stat.org/samples/canada.json",function(){//As previous example but with type "array"//Age is the third dimension (its index is 2)this.toTable({type :"array",content :"id"},function(d,i){if(d[2]==="T"){returnd;}});});
JSONstat("https://json-stat.org/samples/canada.json",function(){//As previous example but with type "object"//Age is the third dimension (its index is 2)this.toTable({type :"object",content :"id"},function(d,i){if(d.c[2].v==="T"){returnd;}});});

Thearrobjtype does not return a table header, butarray andobjecttype do:callback cannot act on the header, only on the data array.

JSONstat("https://json-stat.org/samples/canada.json",function(){//This will not remove the header (row 0 in type "array") but the first data rowthis.toTable({type :"array"},function(d,i){if(i){returnd;}});});

Becausearray andobjecttype includes a header in the result, it is not advisable to change the structure of the data array when using these types: the header will be left untouched and incoherent.

If you need to transform the output deeply use thearrobjtype.

JSONstat("https://json-stat.org/samples/canada.json",function(){//Select only the female population by age group//Get an array of objects with only two properties (age and population)//Change scale of unitsthis.toTable({type :"arrobj",content :"id"},function(d){if(d.sex==="F"&&d.concept==="POP"){return{age :d.age,population :d.value*1000};}});});

Return Value

It depends on thetype specified in theopts parameter.

arrobj type

Unlessmeta istrue, it returns an array of objects, where the key is the dimension ID,value orstatus (columns) and the value can be the category label or ID.

[{"age" :"total","concept" :"population","country":"Canada","sex":"total","value" :34880.5,"year" :"2012"},{"age" :"total","concept" :"population","country":"Canada","sex":"male","value" :17309.1,"year" :"2012"},{"age" :"total","concept" :"population","country":"Canada","sex":"female","value" :17571.3,"year" :"2012"},...]

Whenmeta istrue, it returns an object of objects:

{"meta": {"label":"Population by sex and age group. Canada. 2012","source":"Statistics Canada, CANSIM, table 051-0001","updated":"2012-09-27","id": ["country","year","age","concept","sex"],"status":false,"unit":false,"by":"sex","bylabel":false,"drop": ["year","country"],"prefix":"","comma":false,"dimensions": {"sex": {"label":"sex","role":"classification","categories": {"id": ["T","M","F"],"label": ["total","male","female" ]}},"age": {...},"concept": {...},"country": {...},"year": {...}}},"data": [...]}

The dimensions included in the "meta.dimensions" property are not affected by the value of theby anddrop options.

array type

It returns an array of arrays. The first element in the array contains the column labels or IDs. The next elements can use category labels or IDs.

[["country","year","age group","concepts","sex","Value" ],["Canada","2012","total","population","total",34880.5 ],["Canada","2012","total","population","male",17309.1 ],...]
object type

It returns an object of arrays in theGoogle DataTable format.

{"cols" : [...],"rows" : [...]}

Warning: DataTable declares explicitly the type of the values. JSON-stat does not, so this information must be inferred. Generally, it can safely be assumed that values are numbers. Currently, toTable only performs a very naïf test: if the first value is a number (ornull), it will assign a type ofnumber; otherwise, it will assign a type ofstring.

Slice()


Parent:Dataset
Description: (Available since version 0.11.0) Modifies ajsonstat instance of class "dataset" applying a filter (creates a subset)
Summary:object Slice (object orarray filter] )

Parameters

filter

This parameter is used to define a subset of the original dataset by freezing one or several dimensions by one of its categories. It does not remove any dimension of the original dataset: it only makes the selected dimensions constant (single category dimensions).

The filter can be specified as an object where properties are dimensions IDs and values are categories IDs or a an array of arrays (pairs of dimension ID / category ID)).

JSONstat("https://json-stat.org/samples/galicia.json",function(){varsubset=JSONstat(this).Slice(//Flatten dimensions "birth", "age", "time"://Keep only//category "T" of dimension "birth"//category "T" of dimension "age"//category "2011" of dimension "time"{"birth":"T","age":"T","time":"2011"});});
JSONstat("https://json-stat.org/samples/galicia.json",function(){varsubset=JSONstat(this).Slice(//Flatten dimensions "birth", "age", "time"://Keep only//category "T" of dimension "birth"//category "T" of dimension "age"//category "2011" of dimension "time"[["birth","T"],["age","T"],["time","2011"]]);});

Return Value

It returns ajsonstat instance identical to the original one but with some dimensions "flattened". Whenfilter is wrong,null is returned.

Warning: Keep in mind that this is performed by actually modifying the original dataset. If you want to keep it, clone it first.

JSONstat("https://json-stat.org/samples/galicia.json",function(){varoriginal=JSONstat(JSON.parse(JSON.stringify(this))),subset=JSONstat(this).Slice({"birth":"T","age":"T","time":"2011"})//*this* will be modified;//Compare original, subset and *this*},false//To be able to clone the original dataset);

Public Properties

class

Response class. String ("collection", "bundle", "dataset", "dimension").

varj=JSONstat({ ...}),datasets=[];switch(j.class){case"collection":j.Item({class :"dataset",embedded:false}).forEach(function(e){datasets.push(JSONstat(e.href));//Async. Deprecated.});break;case"bundle":datasets=j.Dataset();break;case"dataset":datasets=[j];//Same as j.Dataset()break;}

coordinates

Category coordinates if the category dimension has ageorole. Array of two numbers (longitude, latitude). If no coordinates have been provided, anull is returned.

error

Optional error information. Object. The properties of this object depend on the provider.

extension

Collection, dataset, dimension or item extended information. Object. The properties of this object depend on the provider.

JSONstat("https://json-stat.org/samples/oecd.json",function(){var//This dataset contains extended propertiesext=this.extension,//Get e-mail of contactemail=ext["contact"];});

hierarchy

true if there is information about the relationship between the categories in the dimension. Boolean.

JSONstat("https://json-stat.org/samples/hierarchy.json",function(){//First dimensionvardim=this.Dimension(0);if(dim.hierarchy){var//First category IDid=dim.id[0],//Array of children's IDsids=dim.Category(0).id;}});

href

Collection, bundle, dataset or dimension URL.

JSONstat("https://json-stat.org/samples/collection.json",function(){//Get the URL of the first item in the collectionvarhref1=this.Item(0).href;});

id

Datasets, dimensions, categories, category children or items IDs. Array of strings.

In the case of category children,id is an array when the dimension includes hierarchical information and the selected category has children. Otherwise it isnull.

In the case of items,id is an array of URLs.

//This example would work also with https://json-stat.org/samples/oecd.jsonJSONstat("https://json-stat.org/samples/oecd-canada.json",function(){if(this.class==="bundle"||this.class==="dataset"){var//"OECD" dataset (if class "bundle")ds=this.Dataset("oecd"),//Dimensions IDs of that datasetdimids=ds.id,//"area" dimension in that datasetdim=ds.Dimension("area"),//Categories IDs of that dimensioncatids=dim.id;if(dim.hierarchy){//Category IDs that belong to OECDvaroecdids=dim.Category("OECD").id;}}});

label

Collection, dataset, dimension, category or item label. String.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Label for "AU" area (Australia)varlabel=this.Dataset("oecd").Dimension("area").Category("AU").label;});

length

Number of datasets, dimensions, categories, category children or items. Integer.

You should always check for length>0 before further processing.

JSONstat("https://json-stat.org/samples/oecd.json",function(){if(this.length){...}else{window.alert("Wrong response!");}});

link

Collection, bundle, dataset or dimension links. Object of relation names.

JSONstat("https://json-stat.org/samples/collection.json",function(){//Get info for IANA link relation "item" in a collection http://www.iana.org/assignments/link-relations/link-relations.xhtmlvaritems=this.link["item"];//Same as this.Item().});

n

Number of values in the dataset. Integer. It is the number of cells in the cube, even if they are empty (missing values).

JSONstat("https://json-stat.org/samples/oecd.json",function(){window.alert("This dataset has "+String(this.n)+" observations.");});

note

Dataset, dimension, category or collection annotations. Array of strings except category annotations, which are an object of strings.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Display general dataset annotations if availablevarnote=this.note;if(note){note.forEach(function(e){window.alert(e);});}//Display annotations for Germany if availablevardenote=this.Dimension("area").Category("DE").note;if(denote){denote.forEach(function(e){window.alert(e);});}});

role

Dimensions withroletime,geo,metric or with unspecified role (classification).null if role information was not included in the response; otherwise, object with four keys (time,geo,metric andclassification). The value of every key is an array of dimensions IDs (ornull if no dimension has the specified role).

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Get the name of the first dimension with a "geo" rolevargeo1=this.role.geo[0];});

Dimension role. String (time,geo,metric; otherwise,classification) ornull (when role information not included in the response).

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Role of the "concept" dimensionvarcrole=this.Dimension("concept").role;});

size

Dimensions sizes. Array. Available since version 0.10.

source

Dataset or collection source. String.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Dataset sourcevarsource=this.source;});

status

As a property of a dataset, status of its values. Array ornull.

JSONstat("https://json-stat.org/samples/oecd.json",function(){if(this.status){//Status of the 23rd valuevarstatus23=this.status[22];}});

As a property of a datum, status of its value. String ornull if not provided.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//Status of the 23rd valuevarstatus23=this.Data(22).status;});

unit

Category unit information if the category dimension has ametricrole. Object. Except "decimals", "label", "symbol" and "position", the rest of the properties of this object depend on the provider. If no unit information has been provided, anull is returned.

JSONstat("https://json-stat.org/samples/oecd.json",function(){//First category in the first dimension with a "metric" rolevarmetric1=this.Dimension({role :"metric"})[0].Category(0);if(metric1.unit&&metric1.unit.hasOwnProperty("decimals")){//Decimals of the first category in the first dimension with a "metric" rolevardec=metric1.unit.decimals;}});

updated

It is the update date of the dataset or collection. String representing a date in an ISO 8601 format recognized by the Javascript Date.parse method.

JSONstat("https://json-stat.org/samples/oecd.json",function(){if(this.updated){varupd=newDate(this.updated),timelapse=Date.now()-upd,days=Math.floor(timelapse/(1000*60*60*24));window.alert("This dataset was updated "+String(days)+" days ago.");}});

value

As a property of a dataset, dataset values. Array.

JSONstat("https://json-stat.org/samples/oecd.json",function(){if(this.value){//23rd valuevarvalue23=this.value[22];}});

As a property of a datum, datum value. Usually a number. Data() returns whatever was included in the cell by the provider (number, string,null...).

JSONstat("https://json-stat.org/samples/oecd.json",function(){//23rd valuevarvalue23=this.Data(22).value;//Same as this.Data( 22, false )});

version

Version of the JSON-stat Javascript Toolkit. String.

varver=JSONstat.version;

This property is not available in the ECMAScript module. If for some reason you need to check the JJT version, you can import it from export.js:

import{JSONstat,versionasJSONstatVersion}from"/your-js-dir/export.js";
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp