# How to write SPARQL query for JSON data?

**URL:** <https://community.stardog.com/t/how-to-write-sparql-query-for-json-data/3191>\
**Category:** Support\
**Created:** [August 9, 2021, 2:34pm UTC](https://community.stardog.com/t/how-to-write-sparql-query-for-json-data/3191 "2021-08-09T14:34:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajakushwah](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@rajakushwah](https://community.stardog.com/u/rajakushwah)\
**Post date:** [August 9, 2021, 2:34pm UTC](https://community.stardog.com/t/how-to-write-sparql-query-for-json-data/3191/1 "2021-08-09T14:34:51Z")

</div>

Hi Team,

I am unable to get the value of 'time' using SPARQL . Please find the details below and please do share the reference document which can help me to guide more on writing SPARQL query to JSON data.

SPARQL query -

SELECT \*  
WHERE {  
?time a :time.  
}

![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/0/05dbb3c2d210ac2a7dd4ab2a1cc85a06d37a407e.png)

![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/c/cbfcac1126b02d3d8b90b06e1700fbefca54469f.png)  
My output -

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/3/3b62bbc4a2173d922c15b208f524d7b1a42543cb.png)

Thanks

---

<div class="post-metadata">

**Author:** ![noahgorstein](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/noahgorstein/32/584_2.png) [@noahgorstein](https://community.stardog.com/u/noahgorstein)\
**Post date:** [August 9, 2021, 3:07pm UTC](https://community.stardog.com/t/how-to-write-sparql-query-for-json-data/3191/2 "2021-08-09T15:07:53Z")

</div>

Hi Raja,

Thanks for your question. You are not getting any results in your query because the graph pattern `?time a :time` does not match any triples currently in the database. You can see exactly which triples are contained in the database after the virtual import by exporting the database as seen here in the documentation: [Importing JSON and CSV Files | Stardog Documentation Latest](https://docs.stardog.com/virtual-graphs/importing-json-csv-files#verify-the-json-import)

If you execute the following query, you should get 1 result, assuming you have only imported the sample JSON file with the example mapping file in the documentation.

```auto
PREFIX : <http://example.com/>

SELECT *
WHERE {
    ?block :time ?time
} 

```

Please also take note of providing the default namespace in the query (e.g. `PREFIX : <http://example.com/>`) If you do not want to provide the default namespace at query time, you can define a new default namespace at the database level. Please see the documentation for managing namespaces here: [Managing Databases | Stardog Documentation Latest](https://docs.stardog.com/operating-stardog/database-administration/managing-databases#namespaces).

Even though the default prefix in the SMS2 mapping defined a default namespace of `http://example.com/` , it does not get persisted at the database level just from the import - you would need to update it at the database level.

Hope that helps.

Cheers,  
Noah

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [August 23, 2021, 3:08pm UTC](https://community.stardog.com/t/how-to-write-sparql-query-for-json-data/3191/3 "2021-08-23T15:08:37Z")

</div>

Closed on August 23, 2021, 3:08pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
