sqliteHow can I store JSON data in a SQLite column?
SQLite is a lightweight database that can be used to store JSON data. To store JSON data in a SQLite column, you can use the JSON1
extension. This extension provides functions for encoding and decoding JSON data, as well as functions for manipulating and querying JSON data.
The following code block uses the json_extract()
function to store JSON data in a SQLite column:
CREATE TABLE json_data (
id INTEGER PRIMARY KEY,
json_column TEXT
);
INSERT INTO json_data (json_column) VALUES (
json_extract('{"name":"John","age":30}', '$.name')
);
SELECT * FROM json_data;
Output example
id json_column
1 John
The code above:
- Creates a table named
json_data
with anid
column and ajson_column
column. - Inserts a JSON string into the
json_column
column. - Selects all data from the
json_data
table.
Helpful links
More of Sqlite
- How do I use SQLite with Zephyr?
- How do I list all tables in a SQLite database?
- How do I download and install SQLite zip?
- How do I set up an ODBC driver to connect to an SQLite database?
- How do I use the SQLite ZIP VFS to compress a database?
- How do I format a date in SQLite using the YYYYMMDD format?
- How do I use SQLite xfilter to filter data?
- How to configure SQLite with XAMPP on Windows?
- How can I use SQLite to query for records between two specific dates?
- How do I use the SQLite sequence feature?
See more codes...