#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 525/week @ 2024-04-01 576/week @ 2024-04-08 336/week @ 2024-04-15 573/week @ 2024-04-22 276/week @ 2024-04-29 493/week @ 2024-05-06 421/week @ 2024-05-13 417/week @ 2024-05-20 238/week @ 2024-05-27 307/week @ 2024-06-03 334/week @ 2024-06-10 565/week @ 2024-06-17 388/week @ 2024-06-24 411/week @ 2024-07-01 303/week @ 2024-07-08 229/week @ 2024-07-15

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