Updated on 2025-09-07 GMT+08:00

Structured Data Functions

This section describes the syntax rules of structured data functions, including parameter description and function examples.

Type

Function

Description

JSON

json_select

Extracts or calculates specific values in JSON expressions based on JMES syntax.

json_parse

Parses a value into a JSON object.

XML

xml_to_json

Converts XML data to JSON data.

json_select

This function extracts or calculates specific values in JSON expressions based on JMES syntax.

  • Function format
    json_select(value, jmes, default=None, restrict=false)
  • Description

    Parameter

    Type

    Mandatory

    Description

    value

    String and JSON

    Yes

    JSON expression or field of the field to be extracted.

    jmes

    String

    Yes

    JMES expression, which indicates the extracted field.

    default

    String

    No

    The value returned if the field to be extracted does not exist. The default value is None, indicating that no field is returned.

    restrict

    Bool

    No

    Whether to strictly restrict the processing when the value of the extracted field is not in the valid JSON format.

    • false (default value): Ignores the error, continues to process the data, and returns the value defined by default.
    • true: Reports an error, discontinues data processing, and discards the log.
  • Returned result

    The extracted value.

  • Function example
    1. Example 1: Extract the value of name from content.
      • Test data
        {
          "content":  {"name": "xiaoming", "age": 10}
        }
      • Processing rule
        e_set("json_filter",json_select(v("content"), "name"))
      • Processing result
        content:  {"name": "xiaoming", "age": 10}
        json_filter:  xiaoming
    2. Example 2: Extract all values of name from content.
      • Test data
        {
          "content":  {"name": ["xiaoming", "xiaowang", "xiaoli"], "age": 10}
        }
      • Processing rule
        e_set("json_filter", json_select(v("content"), "name[*]"))
      • Processing result
        content:  {"name": ["xiaoming", "xiaowang", "xiaoli"], "age": 10}
        json_filter:  ["xiaoming", "xiaowang", "xiaoli"]
    3. Example 3: Extract the value of name3 from content. If the field does not exist, the value of default is returned.
      • Test data
        {
          "content":  {"name": "xiaoming", "age": 10}
        }
      • Processing rule
        e_set("json_filter", json_select(v("content"), "name3", default="None"))
      • Processing result
        content:  {"name": "xiaoming", "age": 10}
        json_filter: None
    4. Example 4: Extract the value of name-test that contains hyphens (-) from content.
      • Test data
        {
          "content":  {"name": {"name-test":"xiaoming"}, "age": 10}
        }
      • Processing rule
        e_set("json_filter", json_select(v("content"), 'name."name-test"', default=None))
      • Processing result
        content:  {"name": {"name-test":"xiaoming"}, "age": 10}
        json_filter: xiaoming
    5. Example 5: Extract the value of name-test that contains hyphens (-) from content. If the element does not exist, no field is returned.
      • Test data
        {
          "content":  {"name": {"name.test":"xiaoming"}, "age": 10}
        }
      • Processing rule
        e_set("json_filter", json_select(v("content"), 'name."name-test"', default=None))
      • Processing result
        content:  {"name": {"name-test":"xiaoming"}, "age": 10}

json_parse

This function parses the value into a JSON object.

  • Function format
    json_parse(value, default=None, restrict=false)
  • Description

    Parameter

    Type

    Mandatory

    Description

    value

    String

    Yes

    Field to be parsed.

    default

    String

    No

    The value returned if the field to be parsed does not exist. The default value is None, indicating that no field is returned.

    restrict

    Bool

    No

    Whether to strictly restrict processing when the value of the field to be parsed is not in the valid JSON format.

    • false (default value): Ignores the error, continues to process the data, and returns the value defined by default.
    • true: Reports an error, discontinues data processing, and discards the log.
  • Returned result

    The converted JSON object.

  • Function example
    1. Example 1: Extract the JSON value of content.
      • Test data
        {
          "content":  {"abc": 123, "xyz": "test" }
        }
      • Processing rule
        e_set("json", json_parse(v("content")))
      • Processing result
        content:  {"abc": 123, "xyz": "test" }
        json:  {"abc": 123, "xyz": "test"}
    2. Example 2: Extract the value of content. If the value is not in JSON format, the value of default is returned.
      • Test data
        {
          "content": "this is not json"
        }
      • Processing rule
        e_set("json", json_parse(v("content"), default="FFF", restrict=false))
      • Processing result
        content: this is not json
        json: FFF

xml_to_json

This function converts XML data to JSON data.

  • Function format
    xml_to_json(source)
  • Description

    Parameter

    Type

    Mandatory

    Description

    source

    String

    Yes

    Field to be converted.

  • Returned result

    The converted JSON data.

  • Function example
    • Test data
      {
        "str": "<data><country name=\"Liechtenstein\"><rank>1</rank><year>2008</year><gdppc>141100</gdppc><neighbor name=\"Austria\" direction=\"E\"/><neighbor name=\"Switzerland\" direction=\"W\"/></country><country name=\"Singapore\"><rank>4</rank><year>2011</year><gdppc>59900</gdppc><neighbor name=\"Malaysia\" direction=\"N\"/></country><country name=\"Panama\"><rank>68</rank><year>2011</year><gdppc>13600</gdppc><neighbor name=\"Costa Rica\" direction=\"W\"/><neighbor name=\"Colombia\" direction=\"E\"/></country></data>"
      }
    • Processing rule
      e_set("str_json",xml_to_json(v("str")))
    • Processing result
      str:<data><country name="Liechtenstein"><rank>1</rank><year>2008</year><gdppc>141100</gdppc><neighbor name="Austria" direction="E"/><neighbor name="Switzerland" direction="W"/></country><country name="Singapore"><rank>4</rank><year>2011</year><gdppc>59900</gdppc><neighbor name="Malaysia" direction="N"/></country><country name="Panama"><rank>68</rank><year>2011</year><gdppc>13600</gdppc><neighbor name="Costa Rica" direction="W"/><neighbor name="Colombia" direction="E"/></country></data> str_json:{"data": {"country": [{"@name": "Liechtenstein", "rank": "1", "year": "2008", "gdppc": "141100", "neighbor": [{"@name": "Austria", "@direction": "E"}, {"@name": "Switzerland", "@direction": "W"}]}, {"@name": "Singapore", "rank": "4", "year": "2011", "gdppc": "59900", "neighbor": {"@name": "Malaysia", "@direction": "N"}}, {"@name": "Panama", "rank": "68", "year": "2011", "gdppc": "13600", "neighbor": [{"@name": "Costa Rica", "@direction": "W"}, {"@name": "Colombia", "@direction": "E"}]}]}}