Dev Helpers
← Back

Index records by their embedded ID

Index records by their embedded ID using SQLite JSON functions.

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