Halaman ini belum tersedia dalam bahasa lokal Anda. Kami berusaha keras untuk menambahkan lebih banyak versi bahasa. Terima kasih atas dukungan Anda.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

get_json_object

Updated on 2025-01-22 GMT+08:00

This function is used to parse the JSON object in a specified JSON path. The function will return NULL if the JSON object is invalid.

Syntax

get_json_object(string <json>, string <path>)

Parameters

Table 1 Parameters

Parameter

Mandatory

Type

Description

json

Yes

STRING

Standard JSON object, in the {Key:Value, Key:Value,...} format.

path

Yes

STRING

Path of the object in JSON format, which starts with $. The meanings of characters are as follows:

  • $ indicates the root node.
  • . indicates a subnode.
  • [] indicates the index of an array, which starts from 0.
  • * indicates the wildcard for []. The entire array is returned. * does not support escape.

Return Values

The return value is of the STRING type.

NOTE:
  • If the value of json is empty or in invalid JSON format, NULL is returned.
  • If the value of json is valid and path is specified, the corresponding string is returned.

Example Code

  • Extracts information from the JSON object src_json.json. An example command is as follows:
    jsonString = {"store": {"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}], "bicycle":{"price":19.95,"color":"red"} }, "email":"amy@only_for_json_udf_test.net", "owner":"Tony" } 

    Extracts the information of the owner field and returns Tony.

    select get_json_object(jsonString, '$.owner'); 

    Extracts the first array information of the store.fruit field and returns {"weight":8,"type":"apple"}.

    select get_json_object(jsonString, '$.store.fruit[0]'); 

    Extracts information about a field that does not exist and returns NULL.

    select get_json_object(jsonString, '$.non_exist_key');
  • Extracts information about an array JSON object. An example command is as follows:

    The value 22 is returned.

    select get_json_object('{"array":[["a",11],["b",22],["c",33]]}','$.array[1][1]'); 

    The value ["h00","h11","h22"] is returned.

    select get_json_object('{"a":"b","c":{"d":"e","f":"g","h":["h00","h11","h22"]},"i":"j"}','$.c.h[*]'); 

    The value ["h00","h11","h22"] is returned.

    select get_json_object('{"a":"b","c":{"d":"e","f":"g","h":["h00","h11","h22"]},"i":"j"}','$.c.h'); 

    The value h11 is returned.

    select get_json_object('{"a":"b","c":{"d":"e","f":"g","h":["h00","h11","h22"]},"i":"j"}','$.c.h[1]');
  • Extracts information from a JSON object with a period (.). An example command is as follows:

    Create a table.

    create table json_table (id string, json string); 

    Insert data into the table. The key contains a period (.).

    insert into table json_table (id, json) values ("1", "{\"city1\":{\"region\":{\"rid\":6}}}"); 

    Insert data into the table. The key does not contain a period (.).

    insert into table json_table (id, json) values ("2", "{\"city1\":{\"region\":{\"rid\":7}}}"); 

    Obtain the value of rid. If the key is city1, 6 is returned. Only [''] can be used for parsing because a period (.) is included.

    select get_json_object(json, "$['city1'].region['id']") from json_table where id =1; 

    Obtain the value of rid. If the key is city1, 7 is returned. You can use either of the following methods:

    select get_json_object(json, "$['city1'].region['id']") from json_table where id =2; 
    select get_json_object(json, "$.city1.region['id']") from json_table where id =2;
  • The json parameter is either empty or has an invalid format. An example command is as follows:

    The value NULL is returned.

    select get_json_object('','$.array[2]'); 

    The value NULL is returned.

    select get_json_object('"array":["a",1],"b":["c",3]','$.array[1][1]');
  • A JSON string involves escape. An example command is as follows:

    The value 3 is returned.

    select get_json_object('{"a":"\\"3\\"","b":"6"}', '$.a');  

    The value 3 is returned.

    select get_json_object('{"a":"\'3\'","b":"6"}', '$.a'); 
  • A JSON object can contain the same key and can be parsed successfully.

    The value 1 is returned.

    select get_json_object('{"b":"1","b":"2"}', '$.b');
  • The result is output in the original sorting mode of the JSON string.

    The value {"b":"3","a":"4"} is returned.

    select get_json_object('{"b":"3","a":"4"}', '$');

Kami menggunakan cookie untuk meningkatkan kualitas situs kami dan pengalaman Anda. Dengan melanjutkan penelusuran di situs kami berarti Anda menerima kebijakan cookie kami. Cari tahu selengkapnya

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback