Dev Helpers
← Back

Slice a JSON array into named pages

Slice a JSON array into named pages using SQLite JSON functions.

Open this example in the interactive library

Source code

SELECT key/2+1 AS page,json_group_array(value ORDER BY key) AS items FROM json_each('["a","b","c","d","e"]') GROUP BY page ORDER BY page;

Sample output

[
  {
    "page": 1,
    "items": "[\"a\",\"b\"]"
  },
  {
    "page": 2,
    "items": "[\"c\",\"d\"]"
  },
  {
    "page": 3,
    "items": "[\"e\"]"
  }
]