This SPARQL query shows the list of US presidents and their spouses. How do I list the spouse names as a nested JSON object and group the query by president ID and president name? Example of a president with multiple spouses: https://www.wikidata.org/wiki/Q22686
Here's the URL for the query:
SELECT ?p ?pLabel ?w ?wLabel WHERE {
wd:Q30 p:P6/ps:P6 ?p .
?p wdt:P26 ?w .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
Spouse: P26
Start time: P580
End time: P582
Wanted to get something like thhis:
{
"pLabel":"John Smith",
"spouses": {
"wLabel":"Jane Doe",
"start_time":"2010-02-10",
"end_time":"2017-05-11"
}
}