SQLite Forum

json_contains Function Idea
Login
I needed something like this a few days ago and implemented it using the <https://github.com/0x09/sqlite-statement-vtab> extension:

```sql
    DROP TABLE IF EXISTS JSON_SET_CONTAINS;
    CREATE VIRTUAL TABLE JSON_SET_CONTAINS USING statement((
      SELECT
        -- TODO: Should JSON_SET_CONTAINS(NULL, ...) return NULL?
        EXISTS(
          SELECT 1 FROM JSON_EACH(?1) each WHERE each.value = ?2
        ) AS value
    ))
    ;
```

```
sqlite> select value from json_set_contains('[3,2,1]', 2);
value
-----
1    
Run Time: real 0.000 user 0.000759 sys 0.000000
```

(My arrays are ordered and contain no duplicate values to make equivalence testing easy, hence the `set` in the name.)