tencent cloud

Cloud Log Service

辞書およびリスト関数

ダウンロード
フォーカスモード
フォントサイズ
最終更新日: 2026-10-12 15:02:20
AI翻訳

辞書関数

json_add関数

関数定義

jsonにノードを追加します。

構文記述

json_add(key,data)

パラメータ説明

パラメータ名
パラメータ説明
パラメータタイプ
必須かどうか
パラメータのデフォルト値
パラメータの値の範囲
key
jsonに対応するキー
string
はい
-
-
data
新しいノードを補充します。
dict
はい
-
-

例

元のログ:
{"content": "{\\"a\\":{\\"b\\":{\\"c\\":\\"cc\\"}}}"}
加工ルール:
json_add("content", {"a":{"b":{"d":"dd"}}})
加工結果:
{"content": "{\\"a\\":{\\"b\\":{\\"c\\":\\"cc\\",\\"d\\":\\"dd\\"}}}"}

json_edit関数

関数定義

ディクショナリ内のキーと値のペアを追加・変更・削除し、dictを返します。

構文記述

json_edit("result", path="", key="",value="333",index=1,mode="edit")

パラメータ説明

パラメータ名
パラメータ説明
パラメータタイプ
必須かどうか
パラメータのデフォルト値
パラメータの値の範囲
field
ネストされたjsonに対応するキー
string
はい
-
-
path
削除または変更する対象フィールドに対応するディレクトリです。削除または変更するフィールドがネストされたjsonの第1階層である場合は、入力しません。配列要素を操作する場合は、配列に対応するkeyまで入力します。JMES構文をサポートします。
string
いいえ
-
-
key
削除または変更する対象フィールドです。配列要素を操作する場合は、入力不要です。
string
いいえ
-
-
value
設定が必要な新しい値です。値を変更する場合のみ入力します。
string
いいえ
-
-
index
配列を操作する場合にこのフィールドを入力します。配列要素は1から始まります。
number
いいえ
0
-
mode
モードです。変更:edit、削除:move。デフォルトはmoveです。
string
いいえ
move
-

例1:指定ノードの値を変更する

元のログ:
{"content":"{\\"p9\\":[\\"0.0\\",\\"0.0\\"],\\"p18\\":\\"CN\\"}","time":"1650440364"}

加工ルール:
json_edit("content", path="", key="p18", value="hello", mode="edit")
加工結果:
{"content":"{\\"p9\\":[\\"0.0\\",\\"0.0\\"],\\"p18\\":\\"hello\\"}", "time":"1650440364"}

例2:指定ノードの値を変更する(複数階層)

元のログ:
{"content":"{\\"p9\\":[\\"0.0\\",\\"0.0\\"],\\"p18\\":\\"CN\\",\\"info\\":{\\"province\\":\\"hubei\\",\\"geo\\":{\\"long\\":\\"111\\",\\"lati\\":\\"222\\"}}}","time":"1650440364"}
加工ルール:
json_edit("content", path="info.geo", key="long", value="333", mode="edit")
加工結果:
{"content":"{\\"p9\\":[\\"0.0\\",\\"0.0\\"],\\"p18\\":\\"CN\\",\\"info\\":{\\"province\\":\\"hubei\\",\\"geo\\":{\\"long\\":\\"333\\",\\"lati\\":\\"222\\"}}}","time":"1650440364"}

例3:ノードを削除する

元のログ:
{"content":"{\\"p9\\":[\\"0.0\\",\\"0.0\\"],\\"p18\\":\\"CN\\",\\"info\\":{\\"province\\":\\"hubei\\",\\"geo\\":{\\"long\\":\\"111\\",\\"lati\\":\\"222\\"}}}","time":"1650440364"}
加工ルール:
json_edit("content", path="", key="p18", mode="move")
加工結果:
{"content":"{\\"p9\\":[\\"0.0\\",\\"0.0\\"],\\"info\\":{\\"province\\":\\"hubei\\",\\"geo\\":{\\"long\\":\\"111\\",\\"lati\\":\\"222\\"}}}","time":"1650440364"}

例4:ノードを削除する(配列要素)

元のログ:
{"content":"{\\"p9\\":[\\"0.0\\",\\"0.0\\"],\\"p18\\":\\"CN\\",\\"info\\":{\\"province\\":[\\"hello\\",\\"world\\"],\\"geo\\":{\\"long\\":[\\"1.0\\",\\"2.0\\"],\\"lati\\":\\"222\\"}}}","time":"1650440364"}
加工ルール:
json_edit("content", path="info.province", index=1, mode="move")
加工結果:
{"content":"{\\"p9\\":[\\"0.0\\",\\"0.0\\"],\\"p18\\":\\"CN\\",\\"info\\":{\\"province\\":[\\"world\\"],\\"geo\\":{\\"long\\":[\\"1.0\\",\\"2.0\\"],\\"lati\\":\\"222\\"}}}","time":"1650440364"}

json_select関数

関数定義

JMES式を使用してJSONフィールド値を抽出し、JMESで抽出したノード値(String)を返します。

構文記述

json_select(data, jmes="")

パラメータ説明

パラメータ名
パラメータ説明
パラメータタイプ
必須かどうか
パラメータのデフォルト値
パラメータの値の範囲
data
フィールド値は、他の関数を使用して抽出できます。
string
はい
-
-
jmes
string
はい
-
-

例

元のログ:
{"field": "{\\"a\\":{\\"b\\":{\\"c\\":{\\"d\\":\\"success\\"}}}}", "status": "500"}
加工ルール:
fields_set("message", json_select(v("field"), jmes="a.b.c.d"))
加工結果:
{"field":"{\\"a\\":{\\"b\\":{\\"c\\":{\\"d\\":\\"success\\"}}}}","message":"success","status":"500"}

json_update関数

関数定義

jsonにKVペアを追加し、ユーザーが渡したStringをペアごとに追加します。ペアになっていない単一のStringは破棄されます(例2を参照)。

構文記述

json_update(json値, key1, value1, key2, value2)

パラメータ説明

パラメータ名
パラメータ説明
パラメータタイプ
必須かどうか
パラメータのデフォルト値
パラメータの値の範囲
field
jsonに対応するキー
string
はい
-
-
可変パラメータ
jsonに追加するkey valueペア
string
はい
-
-

例1:jsonにKVペアを追加する

元のログ:
{"data": "{\\"c\\":\\"d\\"}"}
加工ルール:
json_update("data", "11", "22")
加工結果:
{"data":"{\\"11\\":\\"22\\",\\"c\\":\\"d\\"}"}

例2:jsonにKVペアを追加する。ペアになっていないもの(例の33)は破棄される

元のログ:
{
"data": "{\\"c\\":\\"d\\"}",
"name": "テスト",
"timestamp": 1734567890,
"status": true
}
加工ルール:
json_update("data", "11", "11", "22", "22", "33")
加工結果:
{
"data":"{"11":"11","22":"22","c":"d"}",
"name":"テスト",
"status":"true",
"timestamp":"1734567890"
}

xml_to_json関数

関数定義

XML値を解析してJSON文字列に変換します。入力値はXML文字列構造である必要があります。そうでない場合、変換異常が発生し、dictが返されます。

構文記述

xml_to_json(data)

パラメータ説明

パラメータ名
パラメータ説明
パラメータタイプ
必須かどうか
パラメータのデフォルト値
パラメータの値の範囲
data
フィールド値
string
はい
-
-

例

元のログ:
{"xml_field": "<note><to>B</to><from>A</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>", "status": "500"}
加工ルール:
fields_set("json_field", xml_to_json(v("xml_field")))
加工結果:
{"xml_field":"<note><to>B</to><from>A</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>","json_field":"{\\"to\\":\\"B\\",\\"from\\":\\"A\\",\\"heading\\":\\"Reminder\\",\\"body\\":\\"Don't forget me this weekend!\\"}","status":"500"}

json_to_xml関数

関数定義

JSON文字列値を解析してXML文字列に変換し、Stringを返します。

構文記述

json_to_xml(data)

パラメータ説明

パラメータ名
パラメータ説明
パラメータタイプ
必須かどうか
パラメータのデフォルト値
パラメータの値の範囲
data
フィールド値
string
はい
-
-

例

元のログ:
{"json_field":"{\\"to\\":\\"B\\",\\"from\\":\\"A\\",\\"heading\\":\\"Reminder\\",\\"body\\":\\"Don't forget me this weekend!\\"}", "status": "200"}
加工ルール:
fields_set("xml_field", json_to_xml(v("json_field")))
加工結果:
{"json_field":"{\\"to\\":\\"B\\",\\"from\\":\\"A\\",\\"heading\\":\\"Reminder\\",\\"body\\":\\"Don't forget me this weekend!\\"}","xml_field":"<ObjectNode><to>B</to><from>A</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></ObjectNode>","status":"200"}

if_json関数

関数定義

JSON文字列かどうかを判断し、TRUE/FALSEを返します。

構文記述

if_json(data)

パラメータ説明

パラメータ名
パラメータ説明
パラメータタイプ
必須かどうか
パラメータのデフォルト値
パラメータの値の範囲
data
フィールド値
string
はい
-
-

例

例1
元のログ:
{"condition":"{\\"a\\":\\"b\\"}","status":"500"}
加工ステートメント:
t_if(if_json(v("condition")), fields_set("new", 1))
加工結果:
{"new":"1","condition":"{\\"a\\":\\"b\\"}","status":"500"}
例2
元のログ:
{"condition":"haha","status":"500"}
加工ステートメント:
t_if(if_json(v("condition")), fields_set("new", 1))
加工結果:
{"condition":"haha","status":"500"}

リスト関数

array_get関数

関数定義

配列の値を取得し、Stringを返します。

構文記述

array_get(配列、添字位置)

パラメータ説明

パラメータ名
パラメータ説明
パラメータタイプ
必須かどうか
パラメータのデフォルト値
パラメータの値の範囲
配列
配列
string
はい
-
-
添字位置
配列の何番目の値を取得します。
int
はい
-
-

例1

元のログ:
{
"field1": "[1,2,3]"
}
加工ルール:
fields_set("field2", array_get(v("field1"), 0))
加工結果:
{"field1":"[1,2,3]","field2":"1"}

例2

元のログ:
{
"field1": "['tom','jerry','bobo']"
}
加工ルール:
fields_set("field2", array_get(v("field1"), 0))
加工結果:
{"field1":"['tom','jerry','bobo']","field2":"tom"}



ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック