Il json_group_object() di SQLite function è una funzione aggregata che restituisce un oggetto JSON composto da tutte le coppie nome/valore nell'aggregazione.
In altre parole, costruisce un oggetto JSON dai valori forniti dai suoi argomenti.
Sintassi
json_group_object(NAME,VALUE)
Dove NAME, VALUE rappresenta le coppie nome/valore da utilizzare nell'oggetto JSON risultante.
Esempio
Supponiamo di avere la seguente tabella:
SELECT PetId, PetName
FROM Pets; Risultato:
+-------+---------+ | PetId | PetName | +-------+---------+ | 1 | Homer | | 2 | Yelp | | 3 | Fluff | | 4 | Brush | +-------+---------+
Possiamo usare json_group_object() per generare il risultato come un documento JSON che contiene coppie nome/valore in base alle colonne nella tabella:
SELECT json_group_object(PetId, PetName)
FROM Pets; Risultato:
+--------------------------------------------------+
| json_group_object(PetId, PetName) |
+--------------------------------------------------+
| {"1":"Homer","2":"Yelp","3":"Fluff","4":"Brush"} |
+--------------------------------------------------+