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/S13003115 http://www.w3.org/1999/02/22-rdf-syntax-ns#type geosparql: Geometry
http://statistics.gov.scot/id/statistical-geography/S13003115 geosparql: asWKT POLYGON ((-4.044240305892069 56.12828616254598, -4.050579993047355 56.129008756933445, -4.050434556388032 56.13171978583774, -4.048849078639009 56.13382825200129, -4.045100629680631 56.132306039973685, -4.042648403587126 56.13492038132038, -4.04487880713892 56.13667453598633, -4.041144722691381 56.13833951214022, -4.047500400370991 56.14036596280679, -4.047643643159814 56.14163699034035, -4.0583016287286755 56.14119651409908, -4.062039514256174 56.13951927299063, -4.066307300535255 56.13560795539646, -4.063389877841656 56.13246018382747, -4.068230733734036 56.13126751077549, -4.072666626093631 56.134066177592715, -4.078576158973137 56.135677977398096, -4.084203274012949 56.13622568887797, -4.086572215828564 56.137769146977384, -4.085950970979681 56.14112623986791, -4.082380413823924 56.14114785880288, -4.081203900227787 56.144872030847246, -4.085882340914136 56.14541499566366, -4.0971561104571155 56.14453393300642, -4.104530644118254 56.14942581160277, -4.107582341088488 56.14717741458363, -4.110988619459242 56.146555758622625, -4.106527398423864 56.14210891776871, -4.112193269878905 56.14096243934899, -4.119046992864656 56.14286172840591, -4.1220203842200975 56.1422822272627, -4.124699489071435 56.144538558762115, -4.121920335621156 56.14668657751649, -4.129553932488166 56.14743592993379, -4.1361236539250905 56.14615687096505, -4.141181654170749 56.14609624666748, -4.141890094825175 56.14421739061258, -4.145062663740003 56.14305520031159, -4.13784825826218 56.140251413192445, -4.142807523692805 56.13825666979485, -4.149764532290922 56.13924838237675, -4.15181605587134 56.138027266985645, -4.154981728093437 56.13868380654125, -4.158153378123149 56.137550934621146, -4.162718718231147 56.13997123058324, -4.158682200166226 56.14281970919732, -4.1612166072581385 56.144497232288366, -4.167401741158611 56.14604609969279, -4.171002370390047 56.14472290072692, -4.179314090855712 56.147171925743244, -4.180116175917985 56.144565064453545, -4.1849166094380905 56.14433639877046, -4.1878717520673145 56.14280121582589, -4.190766694754527 56.1447926791345, -4.190211896504271 56.14777176617675, -4.192734815729604 56.1505174631245, -4.196297475089362 56.14988797252705, -4.20597908035519 56.15031937746046, -4.210747815618347 56.14793168203867, -4.215636924561278 56.15019323753309, -4.229278730954812 56.151106241098745, -4.234172229195794 56.14961678890867, -4.235036637327262 56.148116465396186, -4.2397132042205365 56.147168074110176, -4.243756840038001 56.14854073851875, -4.2531033530002045 56.14879835157933, -4.256418706771006 56.14800630986039, -4.2570133206698015 56.14592927239123, -4.255132171773351 56.141547376594936, -4.260645127807404 56.13965093514249, -4.266353702379794 56.140568212796126, -4.27085944781289 56.136204833498404, -4.276517291872002 56.13812013069992, -4.277785270395754 56.137161184507995, -4.285528573835061 56.13862322124779, -4.282992627467152 56.1417572376064, -4.283033852982106 56.14467907591126, -4.289487701818741 56.14573425579374, -4.298408017785516 56.144571820981476, -4.306652401385623 56.14261714623839, -4.307099988708167 56.14514227920117, -4.313793932422284 56.14487680450865, -4.315795274589881 56.14351728913471, -4.325382600136441 56.14251926790091, -4.329579781871969 56.140744303608884, -4.331473284009346 56.14343714016102, -4.33539380589897 56.14031634594191, -4.339221952600505 56.138599236718974, -4.337644755659151 56.1362447327678, -4.3446443434153235 56.13481337487627, -4.348442208022771 56.13200812955364, -4.350380763691926 56.12880680708308, -4.355286910338353 56.12851206044813, -4.366563385940936 56.124595417378224, -4.37138366154195 56.123569135675254, -4.378214566898366 56.12313845980815, -4.38248101380131 56.12172338918311, -4.385937019153026 56.119048428985685, -4.391646707650865 56.11889212668896, -4.394885958714158 56.11776524977709, -4.394336280044908 56.11326773649221, -4.400105251966547 56.111883981123, -4.40370082038601 56.109827810859905, -4.40821227087528 56.109052349606955, -4.4124893150925 56.10574233257894, -4.42490672660049 56.109165869790694, -4.429250684036963 56.109696108423826, -4.437674225739321 56.11381715603177, -4.442609952538247 56.114155453835465, -4.448907378306026 56.11642591700741, -4.462124094744629 56.11883230608038, -4.471853965010975 56.11676842927276, -4.473673240584123 56.11804426153502, -4.4827847165764485 56.11962737586791, -4.487847024656058 56.11879299334362, -4.495588076927862 56.1239215451916, -4.497702799596429 56.12328288475114, -4.502827550957243 56.126402077178746, -4.503169396352659 56.12811993961593, -4.515959707347286 56.12861310152656, -4.529397839167841 56.12996979883039, -4.530248394229003 56.13397443017554, -4.536924281022839 56.133433020799266, -4.539282710054364 56.1353932838486, -4.5425967267669165 56.13524421971552, -4.544609332361731 56.13695991800593, -4.54881413633808 56.13823033114269, -4.547693472332816 56.14112056741294, -4.553845692325554 56.141281103448065, -4.5617991902414206 56.13972318736094, -4.566734454991852 56.140829585292394, -4.569179513736939 56.14309317785368, -4.568160875793558 56.147370081123995, -4.572382767383262 56.15428833707373, -4.579530103974746 56.16241260127045, -4.5792812515872265 56.16614778530092, -4.584207818191646 56.16833491248022, -4.585044649824116 56.16988040230875, -4.589344625280199 56.17002585375634, -4.595976645934691 56.169299741912525, -4.600918863440153 56.167864691669756, -4.607018176996645 56.17074254275752, -4.610958106682965 56.174312977614434, -4.614435699804143 56.179605245843504, -4.614516143920678 56.18232692769644, -4.6189502397780196 56.18408635037712, -4.6148911531356225 56.18736572947677, -4.6143786650587035 56.18973407044194, -4.618695896142671 56.19470916110445, -4.622448148318441 56.19455680919443, -4.625777749096898 56.1965947128151, -4.636418953838209 56.19604279209685, -4.638998856365079 56.196942249933606, -4.646798909905835 56.196875175303795, -4.653404007957484 56.199487493929716, -4.651987117749182 56.20138293325693, -4.650389959105931 56.20720994873055, -4.652973051391279 56.21077585636085, -4.6563599406451575 56.21142932226989, -4.658879416803044 56.21427377896269, -4.664161531347948 56.218637968248665, -4.669677251816682 56.218042559842544, -4.676433975534733 56.21949183364369, -4.685548629464077 56.21910366417188, -4.691814014387625 56.234393712720845, -4.69709401413502 56.24223761280238, -4.698770728371696 56.24564798253657, -4.701475718902938 56.25494109275326, -4.698273922865452 56.25946008847064, -4.697415622603527 56.26309656657351, -4.697790141088474 56.27059338517044, -4.696867012166986 56.274918836454795, -4.693806113354191 56.277681983614926, -4.690195145253911 56.27883009599426, -4.68452046406931 56.278432015935834, -4.679824688629364 56.27701490954183, -4.6720969275153745 56.28168501781381, -4.667249946977158 56.279371798742716, -4.664413526529242 56.28086653724522, -4.66095568532499 56.28086457416983, -4.660944021118362 56.28581264062346, -4.6695392545742544 56.28926318935212, -4.674580999460818 56.288677913107314, -4.678594644315339 56.289107940001635, -4.680122094476561 56.29095785965264, -4.679530564291146 56.29347383695052, -4.682124269015783 56.297848736134966, -4.680786913868765 56.29975621010605, -4.677626647737643 56.29975723285126, -4.674522529509217 56.30183313374248, -4.670674540023101 56.302522921696955, -4.677402149491921 56.3080984142803, -4.676112982727728 56.31000927797175, -4.67671823618353 56.31288140996575, -4.672580202811211 56.31406281619808, -4.667921782199676 56.318684301940735, -4.660797706509356 56.31555248404962, -4.657303842275694 56.31740267903626, -4.658806942725438 56.32215645886707, -4.667338686116301 56.32608941094864, -4.6737442182573385 56.32585240811689, -4.676867604176691 56.3264500173266, -4.682556233710698 56.32556286464493, -4.684289630213167 56.32444677492329, -4.691573764292269 56.322679786481395, -4.695716962625503 56.322481815340815, -4.703134988265957 56.32673769308486, -4.705418228191316 56.32642715337043, -4.708681662848758 56.32853541107174, -4.712522512299122 56.32874344332108, -4.715748912118343 56.32998046868964, -4.719244775028229 56.329544230359346, -4.717215761379213 56.32558006627031, -4.7170956680920035 56.32218518598728, -4.7210014174421975 56.322063461276784, -4.720700431168872 56.32715283293619, -4.728548680875945 56.329222643071645, -4.730688905867084 56.33053272738105, -4.735884127805873 56.331689857550856, -4.7426683237916425 56.331872323250806, -4.749805913350928 56.3266222267545, -4.752773511088509 56.32514958028875, -4.773789440716408 56.323399686120034, -4.785916555443354 56.32384192156853, -4.788958093618318 56.326330598543564, -4.792836503830141 56.33313720416097, -4.785639002703056 56.33561388272658, -4.784724076183115 56.33693774939819, -4.780606592468157 56.33805941167655, -4.780441648901981 56.339573160552334, -4.7835502815423565 56.343480659533846, -4.787131256968098 56.344424755324916, -4.795019649281791 56.347828763322, -4.798546631570436 56.35078718754007, -4.801266306184888 56.35564233763057, -4.807723974886812 56.35528486045047, -4.810208143565994 56.355821760745734, -4.812734069085528 56.35813280185844, -4.818781418884567 56.36021544201464, -4.822835690549894 56.36292748730905, -4.826866299704784 56.364219830435246, -4.831737709521374 56.36680053235395, -4.834765089314138 56.36656774842321, -4.839845329746069 56.368026154716254, -4.853226526461897 56.36926918138837, -4.854375518114458 56.3706853046721, -4.845314024069798 56.375230689889655, -4.836669850515517 56.376615401480585, -4.834237377843192 56.37810475703698, -4.833257139542846 56.38115620144549, -4.834603740644533 56.38259952172192, -4.83590180261616 56.38709093549852, -4.835164785798156 56.390145899476835, -4.8212309976222905 56.39444576787421, -4.812653418878012 56.39811920469458, -4.816153256487215 56.399859875691156, -4.817321063363037 56.402062424523294, -4.816394064689754 56.40607872564941, -4.814153719123392 56.40834072607728, -4.814496113994678 56.41407203491565, -4.811676352678721 56.41760998415856, -4.803802979152121 56.41628275530871, -4.798618979489852 56.416790860935826, -4.795186224769419 56.42271517648612, -4.789603398473589 56.42399134678628, -4.791422735630078 56.42568965604727, -4.789938022691031 56.427340935187516, -4.781617951419084 56.427020094351064, -4.779853708312698 56.42818312959596, -4.766043744413467 56.432114229194816, -4.766413714296877 56.43620005793206, -4.761408394995762 56.43574984356466, -4.752905429567222 56.437071430466155, -4.747457694434237 56.43565977193218, -4.736983828167802 56.433833086117446, -4.734246449617534 56.43400579332297, -4.7263519363603415 56.440793869638554, -4.723055207243889 56.44639933200085, -4.724091698115754 56.449769549557274, -4.728991404576326 56.45314018596881, -4.733340205511944 56.45493191000703, -4.730381432196992 56.45611162288542, -4.724879998173681 56.45986817321279, -4.720832450402201 56.45865826605503, -4.716192969778459 56.45927228361077, -4.704886145958092 56.46177977640834, -4.702945853198093 56.46303095191583, -4.70008787404236 56.46736687148485, -4.6935242959660135 56.465019895304025, -4.689246360827154 56.46226804749183, -4.686487930223302 56.4632086386436, -4.673370654884768 56.461254037486135, -4.6665140650880135 56.46151841009647, -4.664042162799153 56.46389042027082, -4.660759450712066 56.46929510980881, -4.655147588041966 56.47310473233818, -4.64911660884887 56.47371452456383, -4.643134697157961 56.47363085019467, -4.639080439402489 56.476049504151305, -4.633988498495218 56.47276033229498, -4.628485931442314 56.474319575358244, -4.6237331901361305 56.47745792732911, -4.620567815552423 56.48101200964038, -4.625654328376293 56.48351996147676, -4.6255751045289655 56.48589882000038, -4.622478470834149 56.48786966700485, -4.61781066268412 56.488026612874776, -4.614610417409829 56.48944227853455, -4.607963285215779 56.49413879265194, -4.603890268169988 56.49528040204957, -4.600730576278927 56.497566568187175, -4.591691631107627 56.498312776508634, -4.582625457265649 56.50035766251323, -4.578191862718478 56.50482673983473, -4.5741408487575175 56.50560291152393, -4.5691304047959305 56.50337440020875, -4.56220772110246 56.50422296394784, -4.5583722747187565 56.50615348552524, -4.553668600498683 56.505329109748196, -4.541939663855321 56.506014742856436, -4.538716652973834 56.50703335172983, -4.531438622988327 56.50476882652904, -4.528514608859861 56.504909277124035, -4.528766552169144 56.50857101727985, -4.5306322458230115 56.50961593956813, -4.530771691391397 56.51268229984746, -4.532894652267288 56.514045578675486, -4.530153539153308 56.517673903449825, -4.528158622429357 56.5187211007369, -4.5220044740255405 56.519079938363355, -4.5112743199717125 56.52190818568669, -4.507790407320567 56.52331776172011, -4.50732172069902 56.52028500265975, -4.502517986794969 56.51930796229988, -4.499053895717196 56.516452309695914, -4.49711965922185 56.516086822078115, -4.494367043714293 56.51266857846102, -4.490908136992642 56.51197854218556, -4.4829954487312 56.513894069147604, -4.481121262280858 56.512578984262674, -4.477701100938924 56.512975309931015, -4.470105430937076 56.51527909186087, -4.469995035256759 56.51595531366528, -4.460908736644935 56.51772644543516, -4.456931841954103 56.5176972903372, -4.450274272228939 56.519455582471515, -4.448846178316806 56.520881211046735, -4.444232305710521 56.522576299743854, -4.441733918488992 56.52493519171675, -4.437869462564841 56.526287273330155, -4.433915889233961 56.52574470626706, -4.430811342486138 56.52652445010841, -4.425980570510813 56.52485291630593, -4.417377318857716 56.52559136924421, -4.408941586121251 56.52859068227112, -4.402838317969103 56.52683960952426, -4.3963405847740376 56.528875777270954, -4.390304425337264 56.533857680027246, -4.37850533924039 56.53360333840721, -4.373630278624739 56.53730488803363, -4.37425004903615 56.5387623428463, -4.3704948009360765 56.542437855490014, -4.371363233782801 56.54527012202044, -4.369141913207065 56.546561682856556, -4.362014371667411 56.54679622649685, -4.357720743797113 56.544334511124084, -4.341047573948245 56.54027772588417, -4.335173512516212 56.540114175868304, -4.331235529401297 56.539028904907305, -4.334869090035186 56.533451701918025, -4.3331429225513265 56.52931877134448, -4.327578742226439 56.52635864461006, -4.321532879676896 56.51697277526216, -4.318970209776973 56.51587031571363, -4.3105215499719005 56.51500782292565, -4.309159311457693 56.51158672951403, -4.311081721163462 56.50992437221644, -4.307102025580189 56.50608458748476, -4.308025610059975 56.50015868158422, -4.304434512388675 56.49413229355598, -4.29870112199863 56.49308376057295, -4.2973540283353096 56.49122596769551, -4.300457538557041 56.48895774655926, -4.299681027799989 56.48028646000883, -4.296896146533379 56.4750537783961, -4.274682373584065 56.47858131478966, -4.242768352357886 56.48815589550261, -4.194452210396816 56.495329853223836, -4.154490349069322 56.51029568729491, -4.1467298930200425 56.50627390033535, -4.1373565753428 56.50301626831693, -4.130769228456502 56.50232516781448, -4.126280229438494 56.50079806614049, -4.1227119637595715 56.49800596090703, -4.116295909317884 56.49482653131722, -4.108236911871419 56.488367676776136, -4.098625162722565 56.465354778217105, -4.103765424366055 56.46715937000688, -4.110315207428271 56.463781564789635, -4.1158692836041455 56.4625143321167, -4.13157402974887 56.46411024499179, -4.134442906924405 56.46403398149374, -4.136386002857738 56.46163706948368, -4.141627718449342 56.46132652021352, -4.142383989897361 56.45919273073957, -4.148594465470232 56.456645501203965, -4.148138337894404 56.45431686749907, -4.156731789846834 56.44974194922359, -4.159831374754103 56.44502851038543, -4.163200311096068 56.444641808126036, -4.166327939535001 56.44870762979727, -4.176797699566221 56.450474431271374, -4.180122399328353 56.452707596037705, -4.194632591928688 56.45851319694477, -4.198958161204702 56.45949708669031, -4.201974147018055 56.456361184437384, -4.1959229389437 56.40128161944964, -4.19866428021367 56.39710817023339, -4.196657154123533 56.39152258977904, -4.196460756619258 56.38670475654605, -4.240632857152523 56.384399823671146, -4.239163687764852 56.38020703392944, -4.2391578551005145 56.37182702984314, -4.23966523249874 56.36929706939962, -4.238107637565876 56.36689875518898, -4.239672184114197 56.36265571670908, -4.241733079635147 56.35970216467028, -4.242039451321319 56.35279025642806, -4.236246615605653 56.34784438163881, -4.223567861446467 56.34230313404924, -4.227149912973399 56.341295166839295, -4.22919256147553 56.33858929700443, -4.233802595129297 56.33483069647169, -4.236934415458471 56.33361035003374, -4.237513420572523 56.32982093200998, -4.234596612949343 56.326413669563564, -4.230506882698827 56.32645595513481, -4.225704347483018 56.32175681754503, -4.221069419471825 56.31964276523817, -4.211575756077119 56.31823101962198, -4.209448045794512 56.31457101236755, -4.197935808597498 56.31443891017123, -4.196681848349143 56.31217396973323, -4.193837144221224 56.31092134190485, -4.191454264513387 56.30714418691454, -4.188215805986142 56.30422689804912, -4.178386269878531 56.30321398255948, -4.1719783826362145 56.30295363987692, -4.165201566364259 56.30359801285396, -4.161503267724394 56.30323131190123, -4.151055476439744 56.29954006437683, -4.150045642177506 56.29853755314406, -4.139880134085058 56.29782849373694, -4.13534427400048 56.29445594893857, -4.118720899549921 56.28784895266302, -4.115702795944111 56.28103928859797, -4.107882959789687 56.280292019286186, -4.101257436097372 56.27878082807417, -4.093559905066818 56.27892655712963, -4.088529416984675 56.28088076216196, -4.083652257360922 56.281057302289135, -4.07977066900663 56.28350406035411, -4.078511587565297 56.28992358397767, -4.0612444847862745 56.27879053603846, -4.052213741371653 56.273499241503806, -4.038554578030403 56.28027164932948, -4.035373554489898 56.2750094153803, -4.0392572911030795 56.2713230852613, -4.037078015037449 56.269215692951306, -4.030085812014278 56.27090322937215, -4.025641593911302 56.27023911247037, -4.01924615597548 56.271925243505116, -4.005288262891262 56.27494249595265, -3.9764697014053763 56.2532728041069, -3.96708499802322 56.2452942245688, -3.9797230697604955 56.24621863880906, -3.9836054920860224 56.24872922598819, -3.9979408757985095 56.25004330120361, -4.001209472812974 56.24911427549862, -4.006643971740786 56.2499428643064, -4.016891562232643 56.248547761399756, -4.010131147506134 56.23440264965978, -4.009395958395917 56.23204213488532, -4.01449359694687 56.2323680632619, -4.018319258942947 56.23148168778652, -4.016592861365317 56.22841130476532, -4.01844328129304 56.220957357049045, -4.014313933169442 56.21917167268333, -4.011450397876604 56.214754726100175, -4.008516928193602 56.21456963983639, -4.006112874927955 56.21226324337957, -4.007351810398577 56.21005133316517, -4.0006870435813555 56.208930904614746, -3.99760911828827 56.20667208609471, -3.9928011803391135 56.205055678198484, -3.9877043456270895 56.20087192031207, -3.987242379739321 56.19755073271866, -3.9812288519006502 56.19496926000603, -3.9841478041777623 56.19278194341657, -3.9861553044123377 56.18955674164973, -3.986063892101718 56.18650737355193, -3.9842544671352074 56.183703907013324, -3.9703418959444043 56.170245500139615, -3.969439760545296 56.16464424065951, -3.966849439121312 56.16003499735098, -3.9659018885331476 56.15381265858456, -3.9675234732529483 56.14950476047379, -3.9707273258215934 56.144033070822886, -3.9715053504003897 56.13954981051249, -3.9710576054914313 56.135928261523766, -3.9747644779747247 56.13735094589366, -3.975200300762256 56.141141661981244, -3.9816795579502724 56.142341806061594, -3.9823534859456564 56.13980039646665, -3.9807746774094985 56.13532971493409, -3.974866445817189 56.134161728468655, -3.9778270848943342 56.13264781285484, -3.9805875665656347 56.128468891524655, -3.983894682311257 56.128352829622145, -3.9851551913664784 56.12680395242945, -3.9822375674248396 56.12394729541027, -3.9859071996709985 56.1204491804326, -3.9925581896672417 56.12011653470473, -3.9975675832352193 56.12272163003687, -4.005816695988158 56.12109880864988, -4.012168127432751 56.121530199071785, -4.017602917030399 56.122980930364484, -4.014865120931608 56.12828101841021, -4.0205092520180745 56.130297890966546, -4.0233330387678246 56.1304458038609, -4.026947390023877 56.1288300468073, -4.027589505425428 56.12705809316659, -4.0347141403218165 56.12586883758173, -4.036807572753048 56.12973637549535, -4.041301909193054 56.12782438381803, -4.044240305892069 56.12828616254598))
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>