#flatten #json #serde-json #json-object #elasticsearch #elastic #search

bin+lib flatten-serde-json

像 Elasticsearch 一样展平 serde-json 对象

1 个不稳定版本

0.1.0 2022 年 2 月 23 日

#7#flatten

Download history • Rust 包仓库 525/week @ 2024-04-01 • Rust 包仓库 576/week @ 2024-04-08 • Rust 包仓库 336/week @ 2024-04-15 • Rust 包仓库 573/week @ 2024-04-22 • Rust 包仓库 276/week @ 2024-04-29 • Rust 包仓库 493/week @ 2024-05-06 • Rust 包仓库 421/week @ 2024-05-13 • Rust 包仓库 417/week @ 2024-05-20 • Rust 包仓库 238/week @ 2024-05-27 • Rust 包仓库 307/week @ 2024-06-03 • Rust 包仓库 334/week @ 2024-06-10 • Rust 包仓库 565/week @ 2024-06-17 • Rust 包仓库 388/week @ 2024-06-24 • Rust 包仓库 411/week @ 2024-07-01 • Rust 包仓库 303/week @ 2024-07-08 • Rust 包仓库 229/week @ 2024-07-15 • Rust 包仓库

1,341 每月下载量

WTFPL 许可证

10KB
241 代码行

展平 serde Json

这个包展平类似于 Elasticsearch 的格式的 serde_json Object

示例

没有需要做的

{
  "id": "287947",
  "title": "Shazam!",
  "release_date": 1553299200,
  "genres": [
    "Action",
    "Comedy",
    "Fantasy"
  ]
}

展平为

{
  "id": "287947",
  "title": "Shazam!",
  "release_date": 1553299200,
  "genres": [
    "Action",
    "Comedy",
    "Fantasy"
  ]
}

对象

{
  "a": {
    "b": "c",
    "d": "e",
    "f": "g"
  }
}

展平为

{
  "a.b": "c",
  "a.d": "e",
  "a.f": "g"
}

对象数组

{
  "a": [
    { "b": "c" },
    { "b": "d" },
    { "b": "e" },
  ]
}

展平为

{
  "a.b": ["c", "d", "e"],
}

数组中的正常值对象

{
  "a": [
    42,
    { "b": "c" },
    { "b": "d" },
    { "b": "e" },
  ]
}

展平为

{
  "a": 42,
  "a.b": ["c", "d", "e"],
}

对象数组的对象数组的...

{
  "a": [
    "b",
    ["c", "d"],
    { "e": ["f", "g"] },
    [
        { "h": "i" },
        { "e": ["j", { "z": "y" }] },
    ],
    ["l"],
    "m",
  ]
}

展平为

{
  "a": ["b", "c", "d", "l", "m"],
  "a.e": ["f", "g", "j"],
  "a.h": "i",
  "a.e.z": "y",
}

生成的字段名与已存在的字段冲突

{
  "a": {
    "b": "c",
  },
  "a.b": "d",
}

展平为

{
  "a.b": ["c", "d"],
}

依赖

~355–750KB
~17K SLoC