The JSON and XML Parsing Library provides built-in functions for reading and writing structured data inside smart contracts on Alibaba Cloud Blockchain as a Service (BaaS). Use these functions to parse JSON or XML input, extract typed node values, insert data, and release the parser handle when done.
Return value conventions
All functions share a consistent return value pattern:
| Function group | result type | Success value | Failure value |
|---|
property_parse | uint | Non-zero handler | — |
property_destroy, property_set_* | bool | true | false |
property_get_* | int | 1 | 0 |
For property_get_* functions, always check result before using data. A result of 0 means the path was not found or the call failed.
Usage notes
Path format: The path parameter is a dot-separated string that locates a node in the parsed document. For example, to access {"order": {"price": 100}}, use path = "order.price". For XML, use the element tag name hierarchy in the same dot notation.
Handler lifecycle: Always call property_destroy after you finish reading or writing. This releases the memory allocated by property_parse.
property_parse
Parses a JSON or XML string and returns a handler used by all subsequent calls.
Syntax
property_parse(string property_value, int property_type) returns(uint result);
Request parameters
| Name | Required | Type | Description |
|---|
property_value | Yes | string | The data to parse, in JSON or XML format. |
property_type | Yes | int | The format of property_value. 0 = JSON, 1 = XML. |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | uint | The handler for this parse session. Pass this value to all subsequent property_get_*, property_set_*, and property_destroy calls. |
property_destroy
Releases the handler returned by property_parse and frees the associated memory.
Syntax
property_destroy(uint handler) returns(bool result);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | bool | true if the handler was released successfully. false if the call failed. |
property_get_bool
Reads a node of type bool from the parsed document.
Syntax
property_get_bool(uint handler, string path) returns(int result, bool data);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
path | Yes | string | Dot-separated path to the target node (for example, "user.active"). |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | int | 1 if the node was found and read successfully. 0 if the call failed. |
data | Yes | bool | The value of the node at path. |
property_get_int
Reads a node of type int from the parsed document.
Syntax
property_get_int(uint handler, string path) returns(int result, int data);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
path | Yes | string | Dot-separated path to the target node (for example, "order.amount"). |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | int | 1 if the node was found and read successfully. 0 if the call failed. |
data | Yes | int | The value of the node at path. |
property_get_uint
Reads a node of type uint from the parsed document.
Syntax
property_get_uint(uint handler, string path) returns(int result, uint data);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
path | Yes | string | Dot-separated path to the target node (for example, "token.balance"). |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | int | 1 if the node was found and read successfully. 0 if the call failed. |
data | Yes | uint | The value of the node at path. |
property_get_string
Reads a node of type string from the parsed document.
Syntax
property_get_string(uint handler, string path) returns(int result, string memory data);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
path | Yes | string | Dot-separated path to the target node (for example, "product.name"). |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | int | 1 if the node was found and read successfully. 0 if the call failed. |
data | Yes | string memory | The value of the node at path. |
property_set_bool
Creates data in JSON and XML, and inserts data of the bool type.
Syntax
property_set_bool(uint handler, string path, bool data) returns(bool result);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
path | Yes | string | Dot-separated path to the target node. |
data | Yes | bool | The value to set. |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | bool | true if the value was set successfully. false if the call failed. |
property_set_int
Creates data in JSON and XML, and inserts data of the int type.
Syntax
property_set_int(uint handler, string path, int data) returns(bool result);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
path | Yes | string | Dot-separated path to the target node. |
data | Yes | int | The value to set. |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | bool | true if the value was set successfully. false if the call failed. |
property_set_uint
Creates data in JSON and XML, and inserts data of the uint type.
Syntax
property_set_uint(uint handler, string path, uint data) returns(bool result);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
path | Yes | string | Dot-separated path to the target node. |
data | Yes | uint | The value to set. |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | bool | true if the value was set successfully. false if the call failed. |
property_set_string
Creates data in JSON and XML, and inserts data of the string type.
Syntax
property_set_string(uint handler, string path, val data) returns(bool result);
Request parameters
| Name | Required | Type | Description |
|---|
handler | Yes | uint | The handler returned by property_parse. |
path | Yes | string | Dot-separated path to the target node. |
data | Yes | val | The value to set. |
Response parameters
| Name | Required | Type | Description |
|---|
result | Yes | bool | true if the value was set successfully. false if the call failed. |