- Introduction
- Quick Start
- Table Design
- Data Loading
- Overview of data loading
- Load data from a local file system or a streaming data source using HTTP push
- Load data from HDFS or cloud storage
- Routine Load
- Spark Load
- Insert Into
- Change data through loading
- Transform data at loading
- Json Loading
- Synchronize data from MySQL
- Load data by using flink-connector-starrocks
- DataX Writer
- Data Export
- Using StarRocks
- Reference
- SQL Reference
- User Account Management
- Cluster Management
- ADMIN CANCEL REPAIR
- ADMIN CHECK TABLET
- ADMIN REPAIR
- ADMIN SET CONFIG
- ADMIN SET REPLICA STATUS
- ADMIN SHOW CONFIG
- ADMIN SHOW REPLICA DISTRIBUTION
- ADMIN SHOW REPLICA STATUS
- ALTER SYSTEM
- CANCEL DECOMMISSION
- CREATE FILE
- DROP FILE
- INSTALL PLUGIN
- SHOW BACKENDS
- SHOW BROKER
- SHOW FILE
- SHOW FRONTENDS
- SHOW FULL COLUMNS
- SHOW INDEX
- SHOW PLUGINS
- SHOW TABLE STATUS
- UNINSTALL PLUGIN
- DDL
- ALTER DATABASE
- ALTER TABLE
- ALTER VIEW
- BACKUP
- CANCEL BACKUP
- CANCEL RESTORE
- CREATE DATABASE
- CREATE INDEX
- CREATE MATERIALIZED VIEW
- CREATE REPOSITORY
- CREATE RESOURCE
- CREATE TABLE AS SELECT
- CREATE TABLE LIKE
- CREATE TABLE
- CREATE VIEW
- CREATE FUNCTION
- DROP DATABASE
- DROP INDEX
- DROP MATERIALIZED VIEW
- DROP REPOSITORY
- DROP RESOURCE
- DROP TABLE
- DROP VIEW
- DROP FUNCTION
- HLL
- RECOVER
- RESTORE
- SHOW RESOURCES
- SHOW FUNCTION
- TRUNCATE TABLE
- DML
- ALTER ROUTINE LOAD
- BROKER LOAD
- CANCEL LOAD
- DELETE
- EXPORT
- GROUP BY
- INSERT
- PAUSE ROUTINE LOAD
- RESUME ROUTINE LOAD
- ROUTINE LOAD
- SELECT
- SHOW ALTER
- SHOW BACKUP
- SHOW DATA
- SHOW DATABASES
- SHOW DELETE
- SHOW DYNAMIC PARTITION TABLES
- SHOW EXPORT
- SHOW LOAD
- SHOW PARTITIONS
- SHOW PROPERTY
- SHOW REPOSITORIES
- SHOW RESTORE
- SHOW ROUTINE LOAD
- SHOW ROUTINE LOAD TASK
- SHOW SNAPSHOT
- SHOW TABLES
- SHOW TABLET
- SHOW TRANSACTION
- SPARK LOAD
- STOP ROUTINE LOAD
- STREAM LOAD
- Data Types
- Auxiliary Commands
- Function Reference
- Java UDFs
- Window Function
- Date Functions
- convert_tz
- curdate
- current_timestamp
- curtime
- datediff
- date_add
- date_format
- date_sub
- date_trunc
- day
- dayname
- dayofmonth
- dayofweek
- dayofyear
- from_days
- from_unixtime
- hour
- minute
- month
- monthname
- now
- quarter
- second
- str_to_date
- timediff
- timestampadd
- timestampdiff
- to_date
- to_days
- unix_timestamp
- utc_timestamp
- weekofyear
- year
- hours_diff
- minutes_diff
- months_diff
- seconds_diff
- weeks_diff
- years_diff
- Aggregate Functions
- Geographic Functions
- String Functions
- JSON Functions
- Overview of JSON functions and operators
- JSON constructor functions
- JSON query and processing functions
- JSON operators
- Aggregate Functions
- Bitmap Functions
- Array Functions
- cast function
- hash function
- Cryptographic Functions
- Math Functions
- Utility Functions
- System variables
- Error code
- System limits
- SQL Reference
- Administration
- FAQ
- Deploy
- Data Migration
- SQL
- Other FAQs
- Benchmark
- Developers
- Contribute to StarRocks
- Code Style Guides
- Use the debuginfo file for debugging
- Development Environment
- Trace Tools
Overview of JSON functions and operators
This topic provides an overview of the JSON constructor functions, query functions, and processing functions, operators, and path expressions that are supported by StarRocks.
JSON constructor functions
JSON constructor functions are used to construct JSON data, such as JSON objects and JSON arrays.
Function | Description | Example | Return value |
---|---|---|---|
json_object | Converts one or more key-value pairs to a JSON object that consists of the key-value pairs, which are sorted by key in dictionary order. | SELECT JSON_OBJECT(' Daniel Smith', 26, 'Lily Smith', 25) | {"Daniel Smith": 26, "Lily Smith": 25} |
json_array | Converts each element of an SQL array to a JSON value and returns a JSON array that consists of those JSON values. | SELECT JSON_ARRAY(1, 2, 3) | [1,2,3] |
parse_json | Converts a string to a JSON value. | SELECT PARSE_JSON('{"a": 1}') | {"a": 1} |
JSON query functions and processing functions
JSON query functions and processing functions are used to query and process JSON data. For example, you can use a path expression to locate an element in a JSON object.
Function | Description | Example | Return value |
---|---|---|---|
Arrow function | Queries the element that can be located by a path expression in a JSON object. | SELECT {"a": {"b": 1}} -> '$.a.b' | 1 |
json_query | Queries the value of an element that can be located by a path expression in a JSON object. | SELECT JSON_QUERY({"a": 1}, '$.a') | 1 |
json_exists | Checks whether a JSON object contains an element that can be located by a path expression. If the element exists, this function returns 1. If the element does not exist, the function returns 0. | SELECT JSON_EXISTS({"a": 1}, '$.a') | 1 |
json_each | Expands the top-level elements of a JSON object into key-value pairs. | SELECT * FROM JSON_EACH('{"a": 1, "b":{"c": 3, "d": null}} | key | value -----+---- a | 1 b | {"c": 3, "d": null} |
cast | Converts data between a JSON data type and an SQL data type. | SELECT CAST(PARSE_JSON('1') as INT); | 1 |
JSON operators
StarRocks supports the following JSON operators: <
, <=
, >
, >=
, =
, and !=
. You can use these operators to query JSON data. StarRocks does not support the IN
operator. For more information about the JSON operators, see JSON operators.
JSON path expressions
You can use a JSON path expression to query an element in a JSON object. JSON path expressions are of the STRING data type. In most cases, they are used with various JSON functions, such as JSON_QUERY. In StarRocks, JSON path expressions do not completely comply with the SQL/JSON path specifications. For information about the JSON path syntax that is supported in StarRocks, see the following table, in which the following JSON object is used as an example.
{
"people": [{
"name": "Daniel",
"surname": "Smith"
}, {
"name": "Lily",
"surname": "Smith",
"active": true
}]
}
JSON path symbol | Description | JSON path example | Return value |
---|---|---|---|
$ | Denotes a root JSON object. | '$' | { "people": [ { "name": "Daniel", "surname": "Smith" }, { "name": "Lily", "surname": Smith, "active": true } ] } |
. | Denotes a child JSON object. | ' $.people' | [ { "name": "Daniel", "surname": "Smith" }, { "name": "Lily", "surname": Smith, "active": true } ] |
[] | Denotes one or more array indexes. [n] denotes the nth element in an array. Indexes start from 0. | '$.people [0]' | { "name": "Daniel", "surname": "Smith" } |
[*] | Denotes all elements in an array. | '$.people[*].name' | ["Daniel", "Lily"] |
[start: end] | Denotes a subset of elements from an array. The subset is specified by the [start, end) interval, which excludes the element that is denoted by the end index. | '$.people[0: 1].name' | ["Daniel"] |