我的 JSON 值如下:
{
"table": "table_name",
"op_type": "U",
"before": {
"AAAA": "1-1111",
"BBBB": "2022-08-31 03:57:01"
},
"after": {
"AAAA": "1-1111",
"BBBB": "2022-08-31 10:10:34",
"DDDD": "2023-08-31 23:59:59"
}
}
我想像這樣添加 column_names 欄位:
,"changed_columns": "AAAA,BBBB,DDDD"
有沒有辦法做到這一點?
uj5u.com熱心網友回復:
您可以使用以下規范,其中主要思想是排列屬性,以便通過使用連續移位轉換在陣列中生成具有唯一元素的陣列,然后在修改轉換中組合它們,例如
[
{
// combine common key names for each respective values for the attributes
"operation": "shift",
"spec": {
"before|after": {
"*": {
"$": "&"
}
}
}
},
{
// construct an array from those newly formed keys
"operation": "shift",
"spec": {
"*": {
"$": "changed_columns"
}
}
},
{
// make them comma-separated
"operation": "modify-overwrite-beta",
"spec": {
"*": "=join(',',@(1,&))"
}
}
]
網站
編輯:如果您的目標是將新生成的屬性與現有屬性一起保留,那么您可以更喜歡使用以下規范
[
{
"operation": "shift",
"spec": {
"*": "&", //else case
"before|after": {
"*": {
"$": "cc.&",
"@": "&2.&"
}
}
}
},
{
"operation": "shift",
"spec": {
"cc": {
"*": {
"$": "changed_columns"
}
},
"*": "&" //else case
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"changed_columns": "=join(',',@(1,&))"
}
}
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/517056.html
上一篇:使用htaccess縮短url
