What Are JSON Functions? Copy Link
JSON functions are built-in functions provided by a database to perform operations on JSON data. These functions allow you to:
- Create JSON objects or arrays.
- Extract specific values from JSON documents.
- Modify JSON data (insert, update, or remove key-value pairs).
- Validate JSON data.
- Aggregate data into JSON structures.
What Are JSON Operators? Copy Link
JSON operators are symbols or keywords used to interact with JSON data in SQL queries. They are often used to:
- Access specific elements in a JSON document.
- Check if a key or value exists in a JSON document.
- Compare JSON values.
These functions and operators are categorized into scalar functions and aggregate functions.
For more details, see official SQLite JSON Functions And Operators.
Scalar Functions Copy Link
Scalar functions operate on individual JSON values and return a single value. These functions are used for creating, querying, and modifying JSON data.
Aggregate functions Copy Link
Aggregate functions in SQLite perform calculations on multiple rows of data and return a single result.
avg(X)
Copy Link
Computes the average (mean) value of X across all selected rows.
Example: Average Product Price
avg(price)
Output:
250.50
- If the
products
table contains{100, 200, 300, 400}
, the average would be 250.50. - NULL values are ignored in the calculation.
count(X)
Copy Link
Counts the number of non-NULL values in column X.
Example: Count Active Users
count(id)
Output:
25
- Counts all
id
values wherestatus='active'
. - If
count(*)
is used, it counts all rows, including those with NULL values.
group_concat(X,Y)
Copy Link
Returns a comma-separated list (or custom separator Y
) of values in column X.
Example: List of Active Users
group_concat(username, ', ')
Output:
Alice, Bob, Charlie
- All active users’
username
values are concatenated into a string.
max(X)
Copy Link
Returns the highest value in column X.
Example: Highest Order Total
max(total)
Output:
5000
- Finds the highest order total in the
orders
table.
min(X)
Copy Link
Returns the lowest value in column X.
Example: Lowest Product Price
min(price)
Output:
25.99
- Finds the cheapest product price in the
products
table.
sum(X)
Copy Link
Computes the sum of all values in column X.
Example: Total Revenue
sum(total)
Output:
125000
- Sums the
total
column for completed orders. - NULL values are ignored.
total(X)
Copy Link
Similar to sum(X)
, but treats NULL values as 0 instead of ignoring them.
Example: Total Sales, Including NULLs
total(sales)
Output:
120000
- Unlike
sum(X)
, if all rows areNULL
,total(X)
returns 0 instead of NULL.
Don’t stop here! Copy Link
Explore our User Guide.
For a complete tutorial on how to create a Flow, see “How to create a Flow in Wiresk”