2

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"
    }
 }

enter image description here

logi-kal
  • 7,107
  • 6
  • 31
  • 43
kenold
  • 318
  • 3
  • 15
  • 1
    You have two questions: the first one is about working with Wikidata qualifiers, the second one is about JSON serialization structure. Both questions are duplicates. The first one is a duplicate of (e. g.) https://stackoverflow.com/q/46383784/7879193 . The second one is a duplicate of (e.g.) https://stackoverflow.com/q/44622486/7879193 . – Stanislav Kralin Jan 28 '18 at 09:45

0 Answers0