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/S02001363 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S02001363 geosparql: asWKT POLYGON ((-2.799570174975317 56.69258245242242, -2.796636541944824 56.69322293614373, -2.7951811677040515 56.693746077041325, -2.793042700414143 56.69421694390742, -2.79110744084175 56.69442981927858, -2.791316053976257 56.69137709439627, -2.7921662888436773 56.68995270086739, -2.793031455442015 56.68886411815985, -2.7889485119992203 56.6893695810928, -2.787538281667427 56.68879861611335, -2.787352775835276 56.68854689820406, -2.7844477320441112 56.68617375968799, -2.7812270136145565 56.687095658661605, -2.779555937226298 56.68553726260119, -2.7898972978404144 56.68435638104269, -2.7887774513339725 56.68304598219585, -2.789542475539956 56.68285771629894, -2.7883779248129503 56.67987405380711, -2.7871766970324003 56.68003685231598, -2.7865269552041108 56.678376129071296, -2.7812537069855474 56.67862947074479, -2.781842823161099 56.677486042489576, -2.7831971551368158 56.674251826627476, -2.7836576184290074 56.67406865588111, -2.7809257458177825 56.67296281713716, -2.779185247449757 56.67323425829708, -2.775994801623295 56.67283193465264, -2.771859032538739 56.66929098620733, -2.7680293466227965 56.660707973226266, -2.7672412201108556 56.658853138467244, -2.7657561006802545 56.65897118768266, -2.766034782346932 56.65856416735091, -2.765121842862003 56.65830357626263, -2.7655327308031943 56.65763880094561, -2.7694833871347893 56.65794622240952, -2.771116087054939 56.654835573688175, -2.7619515124181593 56.654591261890864, -2.761941179470932 56.64922785348703, -2.7519681456372123 56.64715929107491, -2.750892491317352 56.65039830419392, -2.747141029428127 56.65023665383096, -2.746349202004844 56.65029855199136, -2.739870362874422 56.6499809276374, -2.737889788300647 56.65024422013448, -2.7379070319354617 56.64821601941407, -2.736785338546051 56.64620872467699, -2.7357058205227265 56.64523807991004, -2.731976228628074 56.645100371499616, -2.7281639032335643 56.64425088103278, -2.724212819025036 56.643468294071454, -2.7217931325033478 56.643327188513005, -2.7137671913678933 56.643242609350416, -2.7132436827703836 56.640559390289596, -2.707164382734463 56.63981247601343, -2.696016783521195 56.638676176031986, -2.6959261850231817 56.639438427620036, -2.6936656208272325 56.638990052959045, -2.6911901416614095 56.63913858748046, -2.6901607395734275 56.63990794103472, -2.6892390253926095 56.64032630451437, -2.6884509891134933 56.64092361953119, -2.674647852858689 56.64405377171824, -2.6717983349156444 56.644835133888456, -2.6713413557582397 56.64602289214065, -2.6717941042467928 56.647262717455675, -2.671723298353031 56.64755621982978, -2.67757644672689 56.64814222027957, -2.677247767268233 56.64998062182356, -2.673578508241563 56.64992610184678, -2.6736590841623182 56.653528238250374, -2.6696975260601996 56.653630472436156, -2.666399371373766 56.65343255957455, -2.665246675170723 56.65466053572088, -2.658294733777128 56.65538927148086, -2.6590325541698534 56.65298147572497, -2.658631304858543 56.65287154275968, -2.6583141665356047 56.65208322510175, -2.659399631321565 56.651857201328156, -2.6596431100647013 56.65229578382561, -2.6609135827542514 56.65209366972901, -2.6609826704110096 56.651712571521394, -2.660318445209853 56.649965823629415, -2.661641527815703 56.649046816600006, -2.6634340978519013 56.647346068757784, -2.6628101444246495 56.64594112897235, -2.660512978081726 56.64139846767065, -2.6612026488682115 56.640884497245864, -2.6610641209601837 56.64041466142719, -2.6615973838714626 56.63993467033497, -2.6622430298534865 56.640543727802786, -2.6640849130992605 56.63957659707075, -2.665344637719867 56.63845267372861, -2.6670765309790134 56.63794687459509, -2.6719860912099924 56.63701950813676, -2.6720584971613848 56.638740278894225, -2.6741624447110226 56.63878280216041, -2.6749479028074323 56.63756738547213, -2.677004092489362 56.63754024205325, -2.681840644635446 56.637299269612704, -2.6898771762170504 56.63675046858176, -2.689420191557886 56.63611085158089, -2.688116545839507 56.635938836648144, -2.687348989723744 56.63382823497108, -2.6923089521516084 56.634352876614, -2.6918529481598283 56.631705129488445, -2.693202439615914 56.629739103045914, -2.6951458918954545 56.62745745918249, -2.6966266191403454 56.62715054834506, -2.6968711444037874 56.626268744594, -2.6966050991272152 56.625982745667805, -2.6981242878389113 56.62352159073268, -2.7011886237072806 56.62178840725504, -2.7031289660170263 56.620968892626294, -2.7028034403507974 56.619236812640224, -2.7044219948328307 56.617772243453736, -2.7049146885608963 56.61710463334191, -2.705247314318065 56.61571920505393, -2.704129396685117 56.61343460586167, -2.7053715894099035 56.61277173247776, -2.7138829238026894 56.61139353630712, -2.713358806931375 56.60951887460209, -2.7186881928730338 56.60791598431016, -2.717687842583235 56.606708911185436, -2.7231299693289337 56.60338402600403, -2.7244957234888503 56.60386814477106, -2.7263029320488137 56.60334517053718, -2.729874553826678 56.60595520550201, -2.7345796858018425 56.603304162288, -2.7389329859184612 56.60171728095293, -2.738294197632681 56.59896285883793, -2.7412755608892674 56.59842454979132, -2.7447247064713878 56.59811186133609, -2.7537741722086073 56.59791216778578, -2.755351314826889 56.597815488813595, -2.7597184089194564 56.59773080557018, -2.768625860585734 56.595730668713266, -2.7728877614177834 56.595192922976096, -2.776691000498135 56.59482783106181, -2.7796147108342453 56.594459155361186, -2.781651413148891 56.59440092874862, -2.7836851348779943 56.59348801727777, -2.7836244815589346 56.59227775941243, -2.782708857643695 56.590522633747156, -2.7906083617229567 56.58360876578921, -2.7886871764388914 56.58203975447129, -2.7869236542714937 56.580999781445676, -2.7795814371765952 56.582564356263504, -2.779565729762051 56.579428984479314, -2.7799926002025703 56.577234172285515, -2.7917046308283724 56.5791995494379, -2.790614762137539 56.57689755317822, -2.797658870088498 56.57748145141963, -2.7973723886142614 56.57469819402913, -2.7970639710927463 56.57319082944242, -2.7997260055225905 56.57285029403722, -2.799027153677849 56.571354437798725, -2.806705247140642 56.568888102764866, -2.8036732985713133 56.56558357974717, -2.8012049011311904 56.56505148710379, -2.804875059680125 56.56470434584917, -2.8071570463916804 56.565650858570706, -2.811058257042239 56.56545476582068, -2.8127180934989595 56.56469823569672, -2.812872396550163 56.56354725710389, -2.813958715395985 56.564124122035764, -2.813572418723428 56.565078968021936, -2.81437273793658 56.56521747473432, -2.8152452234228256 56.56719726549107, -2.8179980507778155 56.56505890797931, -2.8316703807395283 56.571895017390396, -2.835354521132909 56.573640207066525, -2.838563342405154 56.567868703012415, -2.846900069450161 56.55788460132452, -2.848973473950424 56.55530096061542, -2.850782058480709 56.553976892303844, -2.8540648460819464 56.55310985663512, -2.8581787992573116 56.55375533782518, -2.8582852966280683 56.55055620378914, -2.864758673164061 56.55195779752654, -2.879443938347388 56.55039929519916, -2.882856225004327 56.5488477722097, -2.8885095052474625 56.546462580618815, -2.8907949975752496 56.54525017444039, -2.8944846392451096 56.53735533402833, -2.8909251532305293 56.53660803987506, -2.891528739974195 56.529604347120014, -2.890744904414167 56.52438276811369, -2.894985079035581 56.52113954672151, -2.894179396027594 56.520101502611986, -2.904940429711866 56.52491235841303, -2.92175461018971 56.52373261204491, -2.9219515865867196 56.52247333888916, -2.9245067557623305 56.522607083953424, -2.9262126760452523 56.523241251647406, -2.9270999022308843 56.524294789547696, -2.9298516941952144 56.52714023807233, -2.9338790264431482 56.53027252917517, -2.9373840340285318 56.530003556133124, -2.9378657093066893 56.53238976407305, -2.939110890856342 56.53934324302987, -2.941304717814739 56.539606991650906, -2.9417489509526473 56.53938427242788, -2.94834686722264 56.538671144893975, -2.950383525858828 56.53803155667666, -2.951901888850341 56.54555294334076, -2.949462321335809 56.54750324394769, -2.9514189113706344 56.548341794650575, -2.972927229897615 56.55489558949841, -2.9746211905931097 56.554343255177535, -2.9776049562029874 56.55271161757978, -2.9781264128885034 56.5514856385902, -2.996476135568251 56.5496597851468, -2.999581329207919 56.55330049622308, -2.9909082884366653 56.55569689593915, -2.985015686536251 56.55619295415681, -3.0020916073388477 56.565184602044354, -3.005566776029357 56.56736669982354, -3.003924965370564 56.57507952413059, -3.0023447203486793 56.57844350905443, -3.000963312294813 56.57977602313446, -2.998682151776564 56.57893361928004, -2.9969932311517598 56.58045411213912, -3.00107101885994 56.58144394847379, -3.000586639692725 56.58237885222773, -3.003785490633358 56.583020599132766, -3.003603513053664 56.58417436698867, -3.005515060595141 56.585039391891954, -3.0061232142454353 56.58328273637008, -3.0140152954250783 56.586309036729425, -3.011913756435459 56.587741823535616, -3.0139403269619587 56.5885552919417, -3.012394948829512 56.5896464563843, -3.019491124883036 56.591942388572086, -3.0202643628763726 56.59163057850202, -3.0230978914149675 56.591634252462775, -3.024722543248895 56.592097047873025, -3.0237940559392675 56.5926886796068, -3.028186012879106 56.59490752457104, -3.0229740349620493 56.597897378673174, -3.0235009109475217 56.5993125828845, -3.0223612642731337 56.59993288394846, -3.020171880152011 56.60270007559711, -3.0175024468860836 56.60337779979202, -3.018347380274719 56.60814157552232, -3.0136577533161493 56.60822480170778, -3.015756269856256 56.612358449195824, -3.0115476814515616 56.613390003950634, -3.014564712011157 56.61835173038206, -3.0136718626216474 56.619086748014716, -3.0127422274127693 56.61930016794172, -3.0152379332360746 56.62083318138302, -3.015006994655095 56.62213911359125, -3.0139999579275423 56.62261189548562, -3.015010807691577 56.62404416333926, -3.0177801662192114 56.62459324864818, -3.017340196543062 56.628072970688095, -3.0062120214452515 56.63208471265545, -3.0066287083969576 56.63426451843618, -3.0109964623812497 56.63383408753822, -3.012133575835353 56.63344997369749, -3.012475797183996 56.63564953022853, -3.0169967272042504 56.635351625903496, -3.0166087227139364 56.63679782870171, -3.020634033631796 56.63673758547344, -3.021137175466368 56.63618066219372, -3.023342531366574 56.63555018422228, -3.026019493955403 56.63611202319445, -3.0291092436085214 56.63474786402298, -3.031083883008972 56.63372289287037, -3.031371887671725 56.63461753717773, -3.032410899778292 56.63655460271762, -3.0328170496423414 56.63753584250534, -3.0333730074156593 56.638248751109074, -3.032465250620595 56.63840848001296, -3.0300347642511936 56.63741749849772, -3.0239533700920966 56.638065816568215, -3.0215034003965804 56.63825684162553, -3.0214353004941854 56.6377068421119, -3.0194383116906693 56.63847969588149, -3.0184665079904995 56.63924413137109, -3.017204321486531 56.63905394287263, -3.0158120347271207 56.639350629767954, -3.015027388998609 56.6411665866577, -3.0131462390453905 56.64186238564762, -3.012249705371852 56.644005399971086, -3.0093367745876227 56.64389317038377, -3.012614069614986 56.64638570744111, -3.012676205670201 56.64712375524454, -3.0140140229029897 56.64885795304992, -3.0145670972846363 56.649751596058344, -3.008580712746031 56.64964475769213, -3.0035647412192006 56.651218800385465, -3.001399774610968 56.65164637783805, -2.99838450919144 56.651724505425456, -2.996598429231001 56.652646229265564, -2.994176269685598 56.65295309510707, -2.991490218173535 56.646937096983976, -2.9864117855390204 56.64792978052065, -2.986735547895988 56.650334994838445, -2.9843360002287493 56.650255167561824, -2.985490368337253 56.65261787550871, -2.9801887478508897 56.65258786322258, -2.976038136636859 56.65291695884725, -2.9754424000331263 56.651322434087916, -2.9699744401426895 56.651158527579284, -2.967303415405547 56.651305093041564, -2.9706701787613343 56.65348002062693, -2.963675420446917 56.654217171397995, -2.966297315633419 56.655966737944624, -2.958908659456867 56.657272680882464, -2.953668908542502 56.65713324940497, -2.9514609832319656 56.65763791567807, -2.944983848228229 56.65620223762321, -2.9442670773989748 56.65558776697123, -2.9409600511544642 56.6557565567097, -2.939106912887842 56.656668970863144, -2.9343436550510833 56.657980569876855, -2.9373073580234768 56.661057835115415, -2.9387972234560427 56.66127121331247, -2.938971052684887 56.66235698911064, -2.940590600285947 56.66318926790287, -2.9415790216939603 56.66487981656442, -2.94141392170679 56.66545605304944, -2.9419893777183024 56.668901626899185, -2.9428672669711773 56.66942504844465, -2.9453346650623504 56.67151762138319, -2.9434640216349326 56.67175641477165, -2.9392305082961943 56.67147397614265, -2.9377455716778234 56.672132029426244, -2.9353933928483595 56.67269774810701, -2.9343057101918415 56.67358637208303, -2.932724368449931 56.6736521330227, -2.930971741009929 56.67405156871493, -2.9288863317224494 56.674192921943416, -2.9255758408953274 56.67428944797835, -2.9246063107877065 56.67468296997631, -2.923620098241581 56.67372898478745, -2.92009478244943 56.67304533729922, -2.918952569600874 56.6723799611873, -2.910981356859159 56.67476543150208, -2.9099954147398255 56.67448514853452, -2.908970579299481 56.67394460165404, -2.9088533011837585 56.67246307429302, -2.9044396213002046 56.67214483219023, -2.9038230994718783 56.672975849832795, -2.903159031140847 56.67448404689575, -2.9016762240646337 56.67601007536365, -2.899250992724416 56.67833654360664, -2.8961288253042627 56.679509019458244, -2.8943712915566024 56.67972828992213, -2.896630294816403 56.68206588367529, -2.8934098764973317 56.683437356696906, -2.888804721258606 56.684829668443385, -2.885580035235742 56.68525916338185, -2.875724425984582 56.686418512190286, -2.874419482743841 56.68367027509569, -2.87373771200878 56.682426262363464, -2.8733528946706546 56.68131493394876, -2.871794706340943 56.67816345026267, -2.8665060689881248 56.67813747648305, -2.8655550238540664 56.6786561843054, -2.8627481108884387 56.679385406936305, -2.8610714321465847 56.67671975384614, -2.8600775533466414 56.67536104096901, -2.852716854620598 56.67678623223113, -2.8459612138879895 56.678287733482826, -2.844626487021135 56.67844952348537, -2.8419350996622925 56.67852165475255, -2.835495140418428 56.67957124706975, -2.830879446518958 56.68046460091225, -2.8267488359573734 56.68115691393284, -2.817746307479816 56.68300418356413, -2.810869724605762 56.68507055885211, -2.8081743795817893 56.6853612575614, -2.8087024984489477 56.68730736368378, -2.8078768795633997 56.68858623514656, -2.8084654351797873 56.68927489556333, -2.8092921101349253 56.689330464973494, -2.8108250010415423 56.690543525900495, -2.8118054873512044 56.69057717142446, -2.813570786551147 56.69086437101536, -2.8126383727452233 56.69138608775943, -2.813606200393535 56.69238246720628, -2.8129556790155736 56.69302933344789, -2.8135277677583472 56.69341337537638, -2.8124949590799666 56.69391174101507, -2.810337833445416 56.6944257911529, -2.8073184781059384 56.691725127788544, -2.806366642093296 56.69121377861609, -2.8046611844659055 56.690941012934125, -2.80332807240256 56.691049772831796, -2.801995432458151 56.69072507246473, -2.799570174975317 56.69258245242242), (-2.89591463527055 56.64848831626211, -2.895337249569475 56.64743541219346, -2.895716691907974 56.64646529392945, -2.8956892127643865 56.645958362380114, -2.898565478810008 56.64569551523876, -2.8987086932643433 56.645298162419074, -2.8984436957411126 56.64424320460039, -2.900028577165987 56.64394351402086, -2.899593152300588 56.64291375149748, -2.9017943463462195 56.64270496666321, -2.902333922784434 56.643241570833204, -2.9039955319989526 56.64294251289003, -2.906856489044693 56.6428458184221, -2.907403696162571 56.64295634228524, -2.9090230137909012 56.642656285531956, -2.9111308960097815 56.642115745625524, -2.910917108691573 56.641712483070556, -2.914668906163435 56.64106572988662, -2.9162952112744116 56.64089205093403, -2.918339913139378 56.63945145673139, -2.9200212360368862 56.63979651965624, -2.9224376539998236 56.63954497988381, -2.9223682510527937 56.63895274349117, -2.9211448689813944 56.6388828786831, -2.9201657159682015 56.63846299552654, -2.9197330999490823 56.63799727212817, -2.917769670208094 56.63834409335073, -2.9168605480012766 56.63731217624126, -2.9175966738052717 56.63690210205232, -2.9166361081090297 56.63622647173809, -2.9177800265635025 56.63579198246312, -2.9184114395930822 56.63625224761602, -2.919190023962738 56.63586874014009, -2.919981072667611 56.636105045784035, -2.922009646959998 56.63558062758192, -2.921100546836021 56.63457704088119, -2.9237237392296 56.63359490187459, -2.9229364374604057 56.63252150616097, -2.9193915046067342 56.63412207854901, -2.915726394628564 56.63558657637503, -2.9100757604966017 56.637685141029316, -2.908005552940407 56.636080602240966, -2.9077636133286813 56.63529453438283, -2.9067118511942946 56.635665720804255, -2.905411123886321 56.63541231408327, -2.906598585252638 56.634979596631204, -2.9039736151488675 56.63360614333374, -2.903267832769154 56.63408743073519, -2.9026676538605387 56.63358919222586, -2.9007389272459174 56.632632354681554, -2.9006780439472895 56.63212968062648, -2.895047741335996 56.63084026063677, -2.895118156120505 56.63182645156046, -2.89434144475145 56.631701999368644, -2.894164525970395 56.63231582162789, -2.892206239612356 56.632033193526965, -2.8919752988604213 56.63258435781292, -2.8919285465152735 56.633693062548936, -2.8912238794332 56.63422817810337, -2.8923058225868865 56.63517274762042, -2.889993577932897 56.63597991400398, -2.889383055640738 56.63566983277714, -2.8882968636583035 56.63592914806789, -2.887425149796453 56.63560295315548, -2.8866317165858715 56.635833213241455, -2.888534706032436 56.63772428484218, -2.889222280060375 56.638536933347886, -2.886975884044134 56.63958878551537, -2.8873551270875475 56.639789465558124, -2.885909911409678 56.64051012217782, -2.8843828773088958 56.64005380668078, -2.8851027886546468 56.6394647177546, -2.8848894807402408 56.63886609231293, -2.883596079338162 56.63667219384098, -2.8827279289668364 56.63691211419124, -2.881312916974438 56.6370569060299, -2.8794326927944787 56.636827635321495, -2.877830456577905 56.637149818081824, -2.879757901374965 56.63889169439665, -2.8764689078225767 56.63978636562721, -2.875570156209448 56.640403614875666, -2.872693889524384 56.64152886876108, -2.873237067279662 56.64174966242048, -2.8713788241348377 56.642481419342936, -2.870770385018213 56.64438133315014, -2.869379179098141 56.644157471348834, -2.8674234253463777 56.64416482895143, -2.8646785389006544 56.64396560627549, -2.8610647088737227 56.644951973393596, -2.85848193664887 56.64539207003833, -2.8589535452604613 56.6458867347341, -2.8623422864365238 56.64498449974919, -2.8622853733860616 56.64550234444656, -2.86334632453455 56.64532832454689, -2.8638942805756797 56.64634066416546, -2.8638245373788513 56.6471844442198, -2.8619533104042385 56.64772054560635, -2.862425898232202 56.6481805296899, -2.862031935953044 56.64869333302702, -2.8601895458828763 56.649486027981084, -2.861876230236308 56.651217280870114, -2.864555036606465 56.6542443313892, -2.8669290355493087 56.65321260414507, -2.8702257206919146 56.65400715570442, -2.870878664012867 56.65402954151126, -2.873749126702138 56.65373316311798, -2.874889730220621 56.653485580349184, -2.8752153854322824 56.65421684577245, -2.8763280494149175 56.65409910539326, -2.876695880891065 56.654800656005094, -2.8742517282203814 56.65645309357296, -2.8747738927920055 56.65671543634281, -2.8781134145465153 56.6544116502067, -2.878757457925945 56.655354105235006, -2.8780641236167406 56.655877104199625, -2.878210067408123 56.65683047741067, -2.881016815733168 56.65677622573576, -2.88093045955493 56.65416741132237, -2.883144641944073 56.6533337509567, -2.884549088273831 56.65342104973201, -2.884417474262344 56.65267630075203, -2.887145663627617 56.652863521499185, -2.8876387393355283 56.65232994134247, -2.8896500173549264 56.65324094979411, -2.891748847024742 56.65371107532741, -2.891131667126444 56.65243974557732, -2.8913195109451015 56.652105995855784, -2.894755632015841 56.65188368230722, -2.895021966179506 56.65238244565013, -2.898493962947563 56.65227622367997, -2.898336121411132 56.650878349163456, -2.8994339643949716 56.65084863417447, -2.9077482146636306 56.65003269808335, -2.9039904699741244 56.64589638574211, -2.90136607241464 56.647307966732626, -2.9009676594523164 56.64769717079404, -2.899215465288033 56.64807819327459, -2.89591463527055 56.64848831626211))
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>