bag_pack()

从键和值的列表创建一个 dynamic JSON 对象(属性包)。

已弃用的别名:pack ()、pack_dictionary ()

语法

bag_pack(key1,value1,key2,value2,... )

参数

名称 类型 必选 说明
字符串 键名称。
value 字符串 键值。

注意

键和值字符串是一个交替列表,列表的总长度必须是偶数。

返回

从列出的键和值输入返回 dynamic JSON 对象(属性包)。

示例

示例 1

以下示例从键和值的交替列表创建并返回属性包。

[单击以运行查询]

print bag_pack("Level", "Information", "ProcessID", 1234, "Data", bag_pack("url", "www.bing.com"))

结果

print_0
{"Level":"Information","ProcessID":1234,"Data":{"url":"www.bing.com"}}

示例 2

以下示例使用两个表,SmsMessages 和 MmsMessages,并从其他列返回其公用列和属性包。 表是作为查询的一部分临时创建的。

SmsMessages

SourceNumber TargetNumber CharsCount
555-555-1234 555-555-1212 46
555-555-1234 555-555-1213 50
555-555-1212 555-555-1234 32

MmsMessages

SourceNumber TargetNumber AttachmentSize AttachmentType AttachmentName
555-555-1212 555-555-1213 200 jpeg Pic1
555-555-1234 555-555-1212 250 jpeg Pic2
555-555-1234 555-555-1213 300 png Pic3

[单击以运行查询]

let SmsMessages = datatable (
    SourceNumber: string,
    TargetNumber: string,
    CharsCount: string
) [
    "555-555-1234", "555-555-1212", "46", 
    "555-555-1234", "555-555-1213", "50",
    "555-555-1212", "555-555-1234", "32" 
];
let MmsMessages = datatable (
    SourceNumber: string,
    TargetNumber: string,
    AttachmentSize: string,
    AttachmentType: string,
    AttachmentName: string
) [
    "555-555-1212", "555-555-1213", "200", "jpeg", "Pic1",
    "555-555-1234", "555-555-1212", "250", "jpeg", "Pic2",
    "555-555-1234", "555-555-1213", "300", "png", "Pic3"
];
SmsMessages 
| join kind=inner MmsMessages on SourceNumber
| extend Packed=bag_pack("CharsCount", CharsCount, "AttachmentSize", AttachmentSize, "AttachmentType", AttachmentType, "AttachmentName", AttachmentName) 
| where SourceNumber == "555-555-1234"
| project SourceNumber, TargetNumber, Packed

结果

SourceNumber TargetNumber Packed
555-555-1234 555-555-1213 {"CharsCount":"50","AttachmentSize":"250","AttachmentType":"jpeg","AttachmentName":"Pic2"}
555-555-1234 555-555-1212 {"CharsCount":"46","AttachmentSize":"250","AttachmentType":"jpeg","AttachmentName":"Pic2"}
555-555-1234 555-555-1213 {"CharsCount":"50","AttachmentSize":"300","AttachmentType":"png","AttachmentName":"Pic3"}
555-555-1234 555-555-1212 {"CharsCount":"46","AttachmentSize":"300","AttachmentType":"png","AttachmentName":"Pic3"}