How decoding of json fields by DBMS tools?

MS SQL. A character string in the list.

#models.py
class Main_search(models.Model):
    list_id = models.TextField(null=True)  #1; [1, 234, 456, 457]

#views.py
import json

jsonDec = json.decoder.JSONDecoder()
qset = Paym_doc.objects.filter(id__in=jsonDec.decode(Main_search.objects.get(id=1).list_id))  # Error, if more than 2500

Can you please provide more details for what you’re asking about?

If you’re getting an error message that you’re looking for help with, please copy/paste the text of the full traceback into your post.

1.
list_id = [x for x in (range(1, 2001))]
qset = Paym_doc.objects.filter(id__in=list_id)
print(qset)
Ok, result
<QuerySet [<Paym_doc: 1>, <Paym_doc: 2>, <Paym_doc: 3>, <Paym_doc: 4>, <Paym_doc: 5>, <Paym_doc: 6>, <Paym_doc: 7>, <Paym_doc: 8>, <Paym_doc: 9>, <Paym_doc: 10>, <Paym_doc: 11>, <Paym_doc: 12>, <Paym_doc: 13>, <Paym_doc: 14>, <Paym_doc: 15>, <Paym_doc: 16>, <Paym_doc: 17>, <Paym_doc: 18>, <Paym_doc: 19>, <
Paym_doc: 20>, '...(remaining elements truncated)...']>

2.
list_id = [x for x in (range(1, 4001))]
qset = Paym_doc.objects.filter(id__in=list_id)
print(qset)
ERROR
('07002', '[07002] [Microsoft][ODBC Driver 17 for SQL Server]COUNT field incorrect or syntax error (0) (SQLExecDirectW)')

3.
Paym_doc.objects.filter(id=3).update(state='1970')  #for the test, other: 'upload', 'wait'...
list_id = [x for x in (range(1, 4001))]
rec = Main_search.objects.filter(id=1).update(list_id=json.dumps(list_id))
qset = Paym_doc.objects.filter(state__in=Main_search.objects.get(id=1).list_id)  #[1, 2, ... 4000]'
print(qset)
no ERROR, no result
<QuerySet []>

4.
jsonDec = json.decoder.JSONDecoder()
qset = Paym_doc.objects.filter(id__in=jsonDec.decode(Main_search.objects.get(id=1).list_id))  #[1, 2, ... 4000]'
print(qset)
ERROR
('07002', '[07002] [Microsoft][ODBC Driver 17 for SQL Server]COUNT field incorrect or syntax error (0) (SQLExecDirectW)')

Problem solved!

Microsoft SQL Server 2014 Express -> 2016 Express (JSON field)
Django==2.2.12 -> Django==4.1.4 (JSONField)
django-mssql-backend -> mssql-django (Django 3, 4)

# models.py
class Main_search(models.Model):
    # list_id = models.TextField(null=True)
    list_id = JSONField(null=True)

# views.py
# qset = Paym_doc.objects.filter(id__in=jsonDec.decode(Main_search.objects.get(id=1).list_id))
qset = Paym_doc.objects.filter(id__in=Main_search.objects.get(id=1).list_id)