JSON Functions
Functions for manipulating data in JSON.
DECODE_JSON(expression)
Example
Example 1. Encode a returned result set as a JSON string.
Query
sql++select ENCODE_JSON(airline) as airline
from `travel-sample`.`inventory`.`airline` airline
where `id` = 10
Result
json5[ { "airline": "{\"callsign\":\"MILE-AIR\",\"country\":\"United States\",\"iata\":\"Q5\",\"icao\":\"MLA\",\"id\":10,\"name\":\"40-Mile Air\",\"type\":\"airline\"}" } ]
ENCODE_JSON(expression)
Example
Example 2. Unmarshal a JSON string into an SQL++ value.
Query
sql++select DECODE_JSON("{\"airline\":{\"callsign\": \"Mile-Air\", \"country\": \"United States\", \"iata\": \"Q5\", \"id\": 10, \"name\": \"40-mile Air\", \"type\": \"airline\"}}") as jsonObj
Result
json5[ { "jsonObj": { "airline": { "callsign": "Mile-Air", "country": "United States", "iata": "Q5", "id": 10, "name": "40-mile Air", "type": "airline" } } } ]
ENCODED_SIZE(expression)
POLY_LENGTH(expression)
Description
Returns length of the value after evaluating the expression. The exact meaning of length depends on the type of the value: