Represent a SQL JSON type. .. note:: :class:`_types.JSON` is provided as a facade for vendor-specific JSON types. Since it supports JSON SQL operations, it only works on backends that have an actual JSON type, currently: * PostgreSQL - see :class:`sqlalchemy.diale
| 2380 | |
| 2381 | |
| 2382 | class JSON(Indexable, TypeEngine[_T_JSON]): |
| 2383 | """Represent a SQL JSON type. |
| 2384 | |
| 2385 | .. note:: :class:`_types.JSON` |
| 2386 | is provided as a facade for vendor-specific |
| 2387 | JSON types. Since it supports JSON SQL operations, it only |
| 2388 | works on backends that have an actual JSON type, currently: |
| 2389 | |
| 2390 | * PostgreSQL - see :class:`sqlalchemy.dialects.postgresql.JSON` and |
| 2391 | :class:`sqlalchemy.dialects.postgresql.JSONB` for backend-specific |
| 2392 | notes |
| 2393 | |
| 2394 | * MySQL - see |
| 2395 | :class:`sqlalchemy.dialects.mysql.JSON` for backend-specific notes |
| 2396 | |
| 2397 | * SQLite as of version 3.9 - see |
| 2398 | :class:`sqlalchemy.dialects.sqlite.JSON` for backend-specific notes |
| 2399 | |
| 2400 | * Microsoft SQL Server 2016 and later - see |
| 2401 | :class:`sqlalchemy.dialects.mssql.JSON` for backend-specific notes |
| 2402 | |
| 2403 | * Oracle 21c and later - see :class:`sqlalchemy.dialects.oracle.JSON` |
| 2404 | for backend-specific notes |
| 2405 | |
| 2406 | :class:`_types.JSON` is part of the Core in support of the growing |
| 2407 | popularity of native JSON datatypes. |
| 2408 | |
| 2409 | The :class:`_types.JSON` type stores arbitrary JSON format data, e.g.:: |
| 2410 | |
| 2411 | data_table = Table( |
| 2412 | "data_table", |
| 2413 | metadata, |
| 2414 | Column("id", Integer, primary_key=True), |
| 2415 | Column("data", JSON), |
| 2416 | ) |
| 2417 | |
| 2418 | with engine.connect() as conn: |
| 2419 | conn.execute( |
| 2420 | data_table.insert(), {"data": {"key1": "value1", "key2": "value2"}} |
| 2421 | ) |
| 2422 | |
| 2423 | **JSON-Specific Expression Operators** |
| 2424 | |
| 2425 | The :class:`_types.JSON` |
| 2426 | datatype provides these additional SQL operations: |
| 2427 | |
| 2428 | * Keyed index operations:: |
| 2429 | |
| 2430 | data_table.c.data["some key"] |
| 2431 | |
| 2432 | * Integer index operations:: |
| 2433 | |
| 2434 | data_table.c.data[3] |
| 2435 | |
| 2436 | * Path index operations:: |
| 2437 | |
| 2438 | data_table.c.data[("key_1", "key_2", 5, ..., "key_n")] |
| 2439 |
no outgoing calls