tencent cloud

피드백

Nested JSON Handling

마지막 업데이트 시간:2024-01-20 17:44:35

    Use Case

    Tom has collected logs to in nested JSON format to CLS. Now he wants to extract the user (secondary nested field) and App fields from the logs.

    Raw Log

    [
    {
    "content": {
    "App": "App-1",
    "start_time": "2021-10-14T02:15:08.221",
    "resonsebody": {
    "method": "GET",
    "user": "Tom"
    },
    "response_code_details": "3000",
    "bytes_sent": 69
    }
    },
    {
    "content": {
    "App": "App-2",
    "start_time": "2222-10-14T02:15:08.221",
    "resonsebody": {
    "method": "POST",
    "user": "Jerry"
    },
    "response_code_details": "2222",
    "bytes_sent": 1
    }
    }
    ]

    DSL Processing Function

    Option 1. Use the JMES formula to extract fields directly without expanding all key-value pairs
    ext_json_jmes("content", jmes="resonsebody.user", output="user")
    ext_json_jmes("content", jmes="App", output="App")
    Option 2. Expand all key-value pairs and discard unwanted fields
    ext_json("content")
    fields_drop("content")
    fields_drop("bytes_sent","method","response_code_details","start_time")

    DSL Processing Function Details

    Option 1:
    1. Use the JMES formula resonsebody.user to directly specify the secondary nested field user.
    ext_json_jmes("content", jmes="resonsebody.user", output="user")
    2. Use the JMES formula App to directly specify the App field.
    ext_json_jmes("content", jmes="App", output="App")
    Option 2:
    1. Use the ext_json function to extract structured data from the JSON data. All fields are expanded by default.
    ext_json("content")
    2. Discard the content field.
    fields_drop("content")
    3. Discard the unwanted fields bytes_sent, method, response_code_details, and start_time.
    fields_drop("bytes_sent","method","response_code_details","start_time")

    Processing Result

    [{"App":"App-1","user":"Tom"},
    {"App":"App-2","user":"Jerry"}]
    
    문의하기

    고객의 업무에 전용 서비스를 제공해드립니다.

    기술 지원

    더 많은 도움이 필요하시면, 티켓을 통해 연락 바랍니다. 티켓 서비스는 연중무휴 24시간 제공됩니다.

    연중무휴 24시간 전화 지원