Open this example in the interactive library
Source code
SELECT json_group_object(json_extract(value,'$.id'),json(value)) AS by_id FROM json_each('[{"id":"a","n":2},{"id":"b","n":4}]');
Sample output
[
{
"by_id": "{\"a\":{\"id\":\"a\",\"n\":2},\"b\":{\"id\":\"b\",\"n\":4}}"
}
]