[
https://issues.apache.org/jira/browse/JENA-632?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13889376#comment-13889376
]
Alexander Dutton edited comment on JENA-632 at 2/3/14 10:46 AM:
----------------------------------------------------------------
If you'd like another perspective, I've been doing something similar to turn
SPARQL resultsets into JSON objects by using carefully crafted variable names.
Rows are grouped using the ?id variable, and underscores in variable names lead
to nested objects. Separately we say which nested objects can appear multiple
times. Hence, a query like this (with 'knows' flagged as an array):
{code}
SELECT * WHERE {
?id a foaf:Person ;
foaf:name ?name .
OPTIONAL {
?id foaf:knows ?knows_id .
?knows_id foaf:name ?knows_name
}
}
{code}
leads to e.g.
{code:json}
[{
"id": "http://example.com/alice",
"name": "Alice",
"knows": [{
"id": "http://example.com/bob",
"name": "Bob"
}, ...]
}, ...]
{code}
For anything remotely complicated it requires some particularly verbose
queries. Something more elegant could probably be done within Jena ;-).
was (Author: alexsdutton):
If you'd like another perspective, I've been doing something similar to turn
SPARQL resultsets into JSON objects by using carefully crafted variable names.
Rows are grouped using the ?id variable, and underscores in variable names lead
to nested objects. Separately we say which nested objects can appear multiple
times. Hence, a query like this (with 'knows' flagged as an array):
{code}
SELECT * WHERE {
?id a foaf:Person ;
foaf:name ?name .
OPTIONAL {
?id foaf:knows ?knows_id .
?knows_id foaf:name ?knows_name
}
}
{code}
leads to e.g.
{code:json}
[{
"id": "http://example.com/alice",
"name": "Alice",
"knows": [{
"id": "http://example.com/bob",
"name": "Bob"
}, ...
}, ...]
{code}
For anything remotely complicated it requires some particularly verbose
queries. Something more elegant could probably be done within Jena ;-).
> Generate JSON from SPARQL directly.
> -----------------------------------
>
> Key: JENA-632
> URL: https://issues.apache.org/jira/browse/JENA-632
> Project: Apache Jena
> Issue Type: Improvement
> Components: ARQ, Fuseki
> Reporter: Andy Seaborne
> Priority: Minor
> Labels: gsoc, gsoc2014, java, javacc
>
> The capability to generate JSON directly from a SPARQL (or extended SPARQL)
> query would enable the creation of JSON data API over published linked data.
> This project would cover:
> # Design and publication of a design.
> # Refinement of design based on community feed
> # Implementation, including testing.
> # Refinement of implementation based on community feed
> Skills required: Java, some parser work, design and discussion with the user
> community, basic understanding of HTTP and content negotiation.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)