将对象数组变成一个包

Turning Array of objects into a bag

我有一个来自 JSON 文件的动态列表需要转换。由于设置,我将始终获得以下输出格式,但我无法确定列表的顺序,只能确定内容。

[
  {"#text": "Foo"
   "@Name": "Bar"}
  {"#text": "Woo"
   "@Name": "Tar"}
  {"#text": "Fuu"
   "@Name": "Bear"}
]

我很想结束:

{"Foo": "Bar", "Woo": "Tar", "Fuu": "Bear"}

我尝试使用 mv-expand,但是,我无法收集列,因为它们被称为#text 和@Name,这意味着它们在查询中使用无效。我对这门语言还很陌生,一直没能找到任何符合我问题的东西。

print obj = dynamic([
  {"#text": "Foo",
   "@Name": "Bar"},
  {"#text": "Woo",
   "@Name": "Tar"},
  {"#text": "Fuu",
   "@Name": "Bear"}
])
| mv-apply obj on (summarize make_bag(pack(tostring(obj['#text']), tostring(obj['@Name']))))
bag_
{"Foo":"Bar","Woo":"Tar","Fuu":"Bear"}

Fiddle