add cart choropleth column cross cube error file folder geo help home lock obs poi rdf remove search slice spreadsheet success table unlock warning

[this is a icon-] developer tool

SPARQL 1.1 Query: Results

Edit query
Query results
s p_blank o_blank
http://statistics.gov.scot/id/statistical-geography/S01010682 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S01010682 geosparql: asWKT MULTIPOLYGON (((-6.3109941178563895 57.481412682748655, -6.310583727392594 57.48082379284882, -6.307273354676377 57.479794938624394, -6.305676181498082 57.47828474030307, -6.304090906001672 57.47404016610782, -6.297305577302009 57.471277216886385, -6.295020583027937 57.47200270807332, -6.289407077150614 57.46826407524839, -6.284382186755304 57.469964033850815, -6.282521962376818 57.46890318550247, -6.206936119617729 57.47344813765776, -6.205846803893837 57.47138022178136, -6.225323912741777 57.46385748251744, -6.2218643061681655 57.45095189108095, -6.225664823168389 57.45020383341797, -6.224586676285741 57.44563567180712, -6.2116492035536 57.444963199383764, -6.213912029251241 57.44057088657021, -6.213522473196336 57.44017098932573, -6.215083065979793 57.43621429965416, -6.215548723115152 57.435284369541655, -6.215641692689012 57.43373744308389, -6.212211777432241 57.433334617199435, -6.204799676485271 57.43062029574942, -6.206961998162829 57.429758792908004, -6.208966355719176 57.42944609761921, -6.206534556180468 57.4283952518252, -6.207603859188299 57.427847965097534, -6.208498063214907 57.427993658507845, -6.2106208085018375 57.42918796751808, -6.211223727914453 57.428647624261544, -6.21560739752748 57.427442525145366, -6.213200504230358 57.42294833161703, -6.211489771626534 57.41927627615114, -6.212251026941607 57.419209581688065, -6.213846813273882 57.42069647511321, -6.215681346572482 57.421698638575485, -6.216616871243102 57.42198572082183, -6.217744028384206 57.421460502436766, -6.215453486877255 57.42017250650535, -6.215634116445052 57.41956398559117, -6.214614847909813 57.41843008521121, -6.216365593954218 57.417628135019854, -6.214974177592597 57.41714524099499, -6.212454102196446 57.415009722853895, -6.214816646740998 57.41421584406349, -6.214513265626982 57.413263998788395, -6.215510776428166 57.41249861450253, -6.212915716892877 57.41134123144297, -6.210740380470863 57.41086358042484, -6.210093260647544 57.411292160467454, -6.208583941489469 57.4110638955486, -6.2061286867360845 57.40956330045544, -6.20688004955415 57.409286353569726, -6.209663691573295 57.40784429634787, -6.213920892881016 57.40675747742037, -6.217842178409281 57.40347851976975, -6.237683862691497 57.4021729649372, -6.2278020571636485 57.39276622874749, -6.235274709934681 57.381183587370465, -6.233508524834092 57.36934537088028, -6.230147049801609 57.36069040775161, -6.232444768976546 57.35507336569616, -6.2341304840838285 57.35035821325717, -6.243728619683149 57.35322692357466, -6.250016723550152 57.3506312297266, -6.255403929464431 57.34802074430345, -6.266157445175006 57.35724277245615, -6.267065774284127 57.360332554666186, -6.270838060299933 57.36200303972018, -6.271402847116641 57.36499655604219, -6.278816216280051 57.36805386925553, -6.283930536322444 57.37236727407457, -6.291162123865882 57.38195919928618, -6.290395310274366 57.38622119437747, -6.293104092752577 57.387594621389425, -6.2894532003495245 57.39055211350023, -6.292036901705688 57.39199278902591, -6.294365779170899 57.39495298765409, -6.296080505026332 57.39679198090885, -6.294502437224474 57.40066803492895, -6.301140579112715 57.39704168199953, -6.309869848527107 57.40185997717541, -6.321182776815657 57.40355818363646, -6.324845705439848 57.411157593622335, -6.340667964083059 57.415576880704705, -6.375426556099722 57.43795377763815, -6.380062557734996 57.438925664101205, -6.389632301545509 57.43041684549934, -6.409826973807143 57.43140135247208, -6.418229710382406 57.43083668799433, -6.438201030553264 57.43588076891741, -6.445762889654791 57.43799717907249, -6.452005145023934 57.437623520693265, -6.457560950826996 57.44160902232935, -6.465656132119523 57.443975209036594, -6.475641702186673 57.45046493000718, -6.48221405488809 57.45780407963, -6.4873416702825 57.44913979675304, -6.489634183355848 57.44634175868207, -6.488646035717141 57.44440727255844, -6.489445570520268 57.44303861381254, -6.491642348155773 57.44421939657189, -6.494162752546867 57.44518171624162, -6.497087058359736 57.44508621695903, -6.497887418364753 57.4453544168643, -6.5020391737239525 57.4461503203532, -6.504084975431222 57.44704848250821, -6.506722922889583 57.45423941198548, -6.510780773636658 57.45453473233695, -6.5159558334792465 57.45711937095497, -6.519648540335024 57.45769734830355, -6.522500633500758 57.45714515713176, -6.524795655756313 57.4580250536988, -6.525254303961091 57.45889900697635, -6.528647939829892 57.46339106053824, -6.534242064231343 57.46596891247198, -6.541037008093356 57.468800028310596, -6.540473877997363 57.47031342921096, -6.531423568918283 57.469488312198, -6.525802809340798 57.469258816262354, -6.517130980637541 57.46703395878813, -6.513064028715347 57.46640633993865, -6.509178008523192 57.47197819694212, -6.52093681506444 57.48416649253946, -6.524968702527277 57.48840190250113, -6.527290360198927 57.50065874981373, -6.528821180686572 57.5045274294822, -6.538602114928333 57.52301505622803, -6.510649936505869 57.515260041582565, -6.503480758117378 57.5136457696127, -6.49727152980538 57.512356607409735, -6.494130696526836 57.5146722895724, -6.490581794237809 57.51476288817457, -6.488230121625856 57.51589003258379, -6.486190600014296 57.51765359293403, -6.481047496432478 57.519520087879634, -6.480057018786129 57.518681363608245, -6.479007150653135 57.517414549602975, -6.4766138376504365 57.515687313420294, -6.472806700362304 57.51367297135374, -6.471917597834574 57.51235092948931, -6.470558441070324 57.510874680078544, -6.469343020895308 57.50982053668184, -6.469189615112317 57.50925035888777, -6.468325690364672 57.508745864169654, -6.4676526980619435 57.50775340810517, -6.466014948312092 57.50666025281657, -6.4649542187426645 57.50618520099285, -6.464845232049749 57.50563592990516, -6.464077927795412 57.50551023105234, -6.462568318623349 57.504165156453716, -6.460904423122311 57.50401724211474, -6.461494766267469 57.50310591914563, -6.464836415939703 57.50112571893106, -6.465020614923444 57.49955871737429, -6.465873897249605 57.4988179279058, -6.465505255730181 57.498399285536166, -6.464052043068461 57.49915234717383, -6.46203237593644 57.49903055492718, -6.460755804587259 57.49952098703812, -6.458283917793308 57.499595033226555, -6.457035824914055 57.50025080733542, -6.455677840807551 57.500622647673055, -6.455101455416637 57.501101734743905, -6.456037418609017 57.502062458890286, -6.455955295044373 57.50241613146995, -6.454691382274854 57.50253279827959, -6.453908712236277 57.50392307337786, -6.452708354329154 57.505040302453224, -6.452728315967599 57.50595698476588, -6.449875369722407 57.50729449190607, -6.447422177027426 57.50773190837392, -6.447075523474179 57.50831526599522, -6.445691361745218 57.508818326596355, -6.445923096717412 57.50941723923449, -6.445502891419104 57.51015158822444, -6.444249301621645 57.51076694377768, -6.442734347529751 57.51115766257476, -6.4400135356555746 57.51310635286819, -6.438434800312015 57.514690959683605, -6.437966439716308 57.51578673231857, -6.437994422240446 57.51642881158709, -6.436208151885633 57.51720225107875, -6.434929345484481 57.51726976513608, -6.434372728640187 57.516884635178734, -6.433441319102222 57.51760994962319, -6.433280228583203 57.51841607551569, -6.431401549219975 57.51877447905836, -6.430223250026267 57.51946348265609, -6.428536470802754 57.519131558850894, -6.428807035167811 57.51874430441558, -6.427210381203422 57.51832825043171, -6.426258734776198 57.51689119661352, -6.426094382779665 57.5162943831257, -6.426476870497675 57.51552096200522, -6.425775876444775 57.51546015169755, -6.425981989042813 57.51467943809921, -6.4254502965252245 57.51436084953757, -6.42636480505514 57.513771097507785, -6.426375034016812 57.51323560340862, -6.428574300798647 57.51166531695219, -6.42876975246387 57.51045326579226, -6.428514669519125 57.510210406251204, -6.429253789426344 57.508934267885785, -6.430223242664689 57.50824811544952, -6.4302259695525885 57.50758247220832, -6.430973197457055 57.507268381885076, -6.430533469368413 57.506468105863654, -6.430800270783997 57.50566545920872, -6.432332043788127 57.504740052626325, -6.432712005846035 57.50418164970211, -6.432324486572886 57.503673642552975, -6.432756112037571 57.50227518958527, -6.433617345044537 57.50204790628948, -6.43536943892977 57.50094381670415, -6.436896360476868 57.50065438878981, -6.437665443972196 57.49999951396707, -6.436782471725057 57.498398228802934, -6.437692212444182 57.49715559042528, -6.4386779709785 57.49675839243064, -6.43952721675012 57.49580207926455, -6.440359887589556 57.493982025933335, -6.443286582977294 57.4918974167254, -6.445262379127802 57.49031849074649, -6.446523623229056 57.48868831814041, -6.446973035748269 57.488415218124935, -6.44885219583546 57.48636116092015, -6.449043495532437 57.48546399577059, -6.449488905693494 57.48528186626482, -6.450142336433684 57.48413452148615, -6.45053890451677 57.48252406788092, -6.450069961801048 57.4814163947222, -6.448459195763652 57.48101013155116, -6.447197217972167 57.481068208998316, -6.445979657543398 57.4816283679217, -6.443726840549024 57.481914768342925, -6.442910678967703 57.48131399662028, -6.440500635050631 57.48126861456706, -6.439357775158981 57.4790784217445, -6.439212485831598 57.478226422101216, -6.438463134383846 57.477555814075885, -6.4390242069379555 57.47667710869725, -6.439096515976783 57.475211243645326, -6.437759806678915 57.47414402540017, -6.43678902956721 57.473628716188635, -6.436354136916247 57.47283818749506, -6.434314085235699 57.47209522056527, -6.434397157978496 57.47173433582616, -6.432385137711456 57.47167568847152, -6.431744043101667 57.47197797225346, -6.4318873782733 57.472774283250494, -6.431639816254667 57.47373365554552, -6.431688984613389 57.47543267285744, -6.432811807801769 57.47603170661933, -6.432601440786834 57.476458230622235, -6.433430557215047 57.479740593283815, -6.433749314253896 57.48044078619983, -6.433891910922254 57.48228941037354, -6.43468928040322 57.48305279046819, -6.436128868358767 57.48403007905983, -6.436381806695158 57.48563107947921, -6.436928705616852 57.486572359105466, -6.436578093809631 57.48879991865645, -6.4359314775846235 57.48989747523569, -6.436430727270686 57.49061109146165, -6.436023275740578 57.49158779673802, -6.434742294211885 57.49197378906819, -6.433552843477307 57.49283861849589, -6.431784666872038 57.49306455243826, -6.431193712311212 57.492379329250795, -6.430519119910695 57.493537197213065, -6.429473802758509 57.493939124556896, -6.428256336031861 57.4948912265618, -6.427896064395901 57.495653085606925, -6.425419878804722 57.49732934773483, -6.421950801894441 57.49803761062291, -6.420824818765883 57.499237349197124, -6.420600434317794 57.500239944441844, -6.42086219510915 57.50277331377902, -6.421606777167628 57.50340282545158, -6.421199596924122 57.50404129274303, -6.419900664925083 57.50428384998454, -6.4200188409774706 57.504997410387375, -6.418208949992148 57.50590543548133, -6.417320618327391 57.50575851753967, -6.414812739216032 57.506629811955584, -6.412734960134476 57.50644360511786, -6.412091827074646 57.50619632269384, -6.409402283277632 57.50660259580286, -6.408181779431515 57.50612637859483, -6.4079305962443565 57.506661305248365, -6.405425226372768 57.507237323465894, -6.4037311820256475 57.50861055172467, -6.40255729786549 57.50836828614082, -6.401276020556196 57.508413065307515, -6.399827018635992 57.508868408112285, -6.399555230819781 57.50938604730159, -6.400073733019405 57.51042919493654, -6.400310004727798 57.511626100439614, -6.401400321848121 57.51373750817809, -6.400309148914219 57.5141128955186, -6.399335731187154 57.51477195942881, -6.401065364038903 57.51733321235801, -6.403366189471406 57.518462465246664, -6.404348123049028 57.51863499436653, -6.4049202626376385 57.51928952065294, -6.406904615693943 57.52312340853498, -6.405993842080898 57.52340259231083, -6.4059223486226085 57.52391773626117, -6.404877044828143 57.523913816278316, -6.403277542697357 57.52423504547728, -6.4039901663440215 57.52612130601774, -6.402963219640422 57.526962137888574, -6.403277513395752 57.527418828107514, -6.401437411908774 57.52796428805583, -6.400971782789644 57.528331308471905, -6.399471947494669 57.52864900307277, -6.398571092114625 57.52804190243341, -6.391551513507659 57.52549423029551, -6.388095344622499 57.522822122061285, -6.386957757296406 57.5222591649069, -6.385408939012308 57.52189038654639, -6.383671086083276 57.520435440801826, -6.383375531493066 57.51964529124152, -6.382539991883129 57.51846471738279, -6.382705220542229 57.51789237034584, -6.383515521796874 57.51719415113909, -6.383189652951968 57.5163600882657, -6.381216120716296 57.51454008029365, -6.380502261633118 57.51277067856427, -6.379861614110934 57.51174969578582, -6.378396672709396 57.510474066750554, -6.377922260012372 57.50937534852641, -6.377897260215222 57.50858208137916, -6.37704315544679 57.50729869783105, -6.376210861244443 57.504510820705654, -6.375991541939657 57.50435385802407, -6.375360669829094 57.501683990090065, -6.37443137616086 57.50102556273918, -6.372837409528644 57.50138669953275, -6.372123584351757 57.501898934761975, -6.37211518528089 57.502414558930894, -6.3714471154872045 57.50287663592537, -6.37100333053196 57.50392809913581, -6.370402399952105 57.50458839639123, -6.366919764634773 57.50406615527383, -6.366342979423863 57.50413291896018, -6.364585209284326 57.50297252061253, -6.362337881450412 57.50109788305081, -6.360369749088783 57.50063542064, -6.35925699261872 57.50063437018073, -6.357331507049459 57.49929711512921, -6.356489623900173 57.49911579218814, -6.355773516521684 57.498238513009134, -6.35507198604489 57.49787515475287, -6.352387188054598 57.49693371876827, -6.35095505220249 57.49698500473661, -6.349708924869843 57.49645246861243, -6.350047050671993 57.49596773242924, -6.349154319504997 57.495681096724404, -6.34852215839673 57.49504370562742, -6.349491571331883 57.494431946602525, -6.349337422529853 57.493628757034394, -6.348214941556455 57.492814939267824, -6.348715699955222 57.4922373537488, -6.348305201898273 57.49078199562308, -6.348532273210042 57.48926684777405, -6.34813116990883 57.48860528899379, -6.34837669912711 57.487455538172775, -6.34772007353406 57.486821688796375, -6.347563627860698 57.484385362579296, -6.347810865508576 57.48259072106743, -6.345632084483891 57.48266324221076, -6.345547260179667 57.4819502900385, -6.344518559434621 57.48095244231514, -6.344149593673945 57.48175300062869, -6.343512498492878 57.482068167665744, -6.3420338591676835 57.48161103959467, -6.340282400136275 57.482272191130114, -6.341193585254481 57.483054683691236, -6.34119458299001 57.48389193879541, -6.340078806684115 57.485167901216606, -6.339662996920506 57.48723363523066, -6.340308124657106 57.48848846729732, -6.339685822020545 57.48939307093224, -6.3405036724332815 57.49004928260493, -6.340106931617687 57.49030847825621, -6.341098444058955 57.49148391776265, -6.340541372334826 57.49185566346305, -6.3374618243962315 57.49119733404373, -6.337118207658919 57.49073701499172, -6.335291818193318 57.490039963855075, -6.335455288724891 57.48934903792444, -6.334686873551775 57.48827829644708, -6.334504507314327 57.4871639957489, -6.333098154869596 57.483544890763106, -6.333225928540318 57.48218698633021, -6.334149589437376 57.48059933440623, -6.333274678723995 57.47961409425971, -6.3318072922634565 57.47863034941724, -6.331411803885029 57.47780127505589, -6.329657868293882 57.476215815398184, -6.328041438826055 57.47500063096672, -6.327568138483008 57.47442963393805, -6.327211062261415 57.47304973314239, -6.327703727806402 57.47158576252148, -6.327646366267418 57.47042489019425, -6.328129542746948 57.47007912058659, -6.3281002501098 57.469098949409215, -6.328510413929739 57.46822148098004, -6.328331782833862 57.46629044760616, -6.328751987625837 57.46566714515005, -6.328094552368977 57.4649918655895, -6.328791624941859 57.46411352263738, -6.328322633523281 57.4635918461179, -6.328373934604779 57.46285532198437, -6.32675654430101 57.461485479708564, -6.32639233452959 57.459254150443726, -6.325312791874913 57.45777407172397, -6.3210507516894445 57.45602017529604, -6.319424723800753 57.45561733155852, -6.3164236298517515 57.45546668417044, -6.315854102391826 57.455659787381954, -6.314195511029958 57.45550351191506, -6.313465609148045 57.45518588486814, -6.312350646535435 57.4554795040027, -6.312540829667378 57.456002693588005, -6.313426798556756 57.45634195735683, -6.312215352861113 57.45676568695436, -6.312574130303697 57.45728939526438, -6.3136538259466555 57.45787023542255, -6.3128999082341934 57.45824051674828, -6.314283502406567 57.45878036070909, -6.316162963806398 57.46017014362314, -6.318361746604994 57.46099855344747, -6.3194912635049025 57.46194276795935, -6.321155809747871 57.46402425262065, -6.321358148497583 57.46474756652932, -6.3206717836204644 57.465153345881724, -6.319960857800789 57.4661139542438, -6.32014686047522 57.4665014792089, -6.31909290524456 57.4679352125049, -6.318624402456445 57.46894235253712, -6.319065610517939 57.470189880057035, -6.318993812212724 57.47119240270433, -6.318303753404565 57.47211900674466, -6.318522399844875 57.47331931126032, -6.3201678307905995 57.47471258252002, -6.320719086666862 57.47547788391672, -6.322458760903029 57.47691825703505, -6.323170136131296 57.47731472020623, -6.324163398692962 57.47842816164369, -6.325033833516115 57.4789972206792, -6.3256548013398 57.479940875495885, -6.325963365790098 57.48215163546805, -6.325859787118932 57.48378659072856, -6.32539202901341 57.486111256432416, -6.322677576647164 57.48689426228146, -6.322227774476686 57.48667767462842, -6.320580946423303 57.48684481080594, -6.318774298103048 57.48605602003085, -6.318076125863122 57.48519322272376, -6.316657315703435 57.4845340968082, -6.315521429725233 57.48364042642147, -6.313690118228288 57.48255563415418, -6.312201858236308 57.482367391718356, -6.3109941178563895 57.481412682748655)), ((-6.413910748845474 57.52824742846653, -6.4134258045934605 57.52803957198849, -6.4141000530896015 57.52704911951371, -6.413808842187044 57.52526506123709, -6.414605619706321 57.52487289586946, -6.416029116649959 57.52496241161152, -6.416176680283143 57.525766681156796, -6.417013343136479 57.5263938989124, -6.417103192453701 57.527411545612935, -6.41610965003034 57.528111915295405, -6.4145699689858295 57.52844468010684, -6.413910748845474 57.52824742846653)), ((-6.405965061103149 57.532779578885844, -6.403858739643713 57.53195383990962, -6.404641247812585 57.53123397042565, -6.405809300176439 57.530729955055754, -6.406297306240352 57.531931542503834, -6.40688147924949 57.53254517170576, -6.405965061103149 57.532779578885844)))
SPARQL API: The Basics

The most flexible way to access the data is by using SPARQL, a query language, analagous to SQL for relational databases, for retrieving and manipulating data from graph databases like ours. We support SPARQL 1.1 query syntax. Many online tutorials are available.

To submit a SPARQL query from your code, you issue an HTTP GET or POST to our endpoint:http://statistics.gov.scot/sparql, with the query itself as a url-encoded parameter called query.

For example, to run the following simple SPARQL query and get the results as JSON:

SELECT * WHERE {?s ?p ?o} LIMIT 10

Option 1: POST (recommended)

Issue a POST to the endpoint, with the query in the body, and an Accept header of sparql-results+json:

POST http://statistics.gov.scot/sparql HTTP/1.1
Host: statistics.gov.scot
Accept: application/sparql-results+json
Content-Type: application/x-www-form-urlencoded

query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Option 2: GET

Issue a GET to the following URL (note the .json extension - see the formats section for more detail on this):

GET http://statistics.gov.scot/sparql.json?query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

Scroll down to the end of this page for examples of both of these methods in a few different languages.

Results formats

As with other aspects of our API, to get the data in different formats, you can use either (a) a format extension or (b) an HTTP Accept header. Available result formats depend on the type of SPARQL query. There are four main forms:

SELECT queries return tabular results, and the formats available reflect this:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
CSV .csv text/csv

CONSTRUCT and DESCRIBE queries return graph data, so the results are available in the same formats as our resource APIs:

Format Extensions Accept Headers
RDF/XML .rdf application/rdf+xml
N-triples .nt, .txt, .text application/n-triples,
text/plain
Turtle .ttl text/turtle
JSON-LD .json application/ld+json,
application/json

ASK queries return a boolean result:

Format Extensions Accept Headers
XML .xml application/xml,
application/sparql-results+xml
JSON .json application/json,
application/sparql-results+json
Text .txt, .text text/plain
Results pagination

We accept page and per_page parameters for paginating the results of SELECT queries (we automatically modify your query to apply LIMIT and OFFSET clauses). For other query types (i.e. DESCRIBE, CONSTRUCT, ASK), pagination like this doesn’t make so much sense, so these parameters are ignored.

For requests made through the website (i.e. HTML format), the page size is defaulted to 20. For requests to our sparql endpoint for data formats (i.e. non-HTML), there will be no defaults for these parameters (i.e. results are unlimited. For performance reasons we generally advise LIMITing your query if possible).

Parameter Substitution

You can parameterise your SPARQL by including %{tokens} in your queries, and providing values for the tokens in the request parameters.

Note that the following tokens are reserved and cannot be used as parameters for substitution:

  • controller
  • action
  • page
  • per_page
  • id
  • commit
  • utf8
  • query
Cross Origin Resource Sharing

Our servers are configured to allow access from all domains. This means that if you’re writing JavaScript to request data from our server in to a web page hosted on another domain, your browser should check this header and allow it.

If you need to support very old browsers, you can additionally pass a callback parameter and the results will be wrapped in that function. For example:

http://statistics.gov.scot/sparql.json?callback=myCallbackFunction&query=SELECT+%2A+WHERE+%7B%3Fs+%3Fp+%3Fo%7D+LIMIT+10

This help topic on the jQuery website has more details.

Examples

Using cURL

Here’s a couple of examples running a query using the widely available cURL command line program.

Request the results as XML, using a POST:

curl -X POST -H "Accept: application/sparql-results+xml" -d "query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010" http://statistics.gov.scot/sparql

Request the results as JSON, using a GET:

curl -X GET -H "Accept: application/sparql-results+json" http://statistics.gov.scot/sparql?query=SELECT%20*%20WHERE%20%7B%3Fs%20%3Fp%20%3Fo%7D%20LIMIT%2010

Using JavaScript

This example HTML page uses jQuery to issue a POST to our SPARQL endpoint, requesting the results as JSON.

<!DOCTYPE html>
<html>
<head>
	<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
</head>
<body>
<script type='text/javascript'>

	var query = 'SELECT * WHERE {?s ?p ?o} LIMIT 10';
	var url = 'http://statistics.gov.scot/sparql.json';
	$.ajax({
		method: 'POST',
		dataType: 'json',
		url: url,
		data: {query: query},
		success: function(data) {
			alert('success: ' + data.results.bindings.length + ' results');
			console.log(data);
		}
	});
</script>
</body>
</html>