#flatten #serde-json #json

bin+lib flatten-serde-json

Flatten serde-json objects like elastic search

1 unstable release

0.1.0 Feb 23, 2022

#13 in #flatten

Download history 1415/week @ 2025-06-05 1392/week @ 2025-06-12 1708/week @ 2025-06-19 1645/week @ 2025-06-26 1197/week @ 2025-07-03 1706/week @ 2025-07-10 1025/week @ 2025-07-17 1546/week @ 2025-07-24 1265/week @ 2025-07-31 1171/week @ 2025-08-07 816/week @ 2025-08-14 2135/week @ 2025-08-21 1659/week @ 2025-08-28 1518/week @ 2025-09-04 1870/week @ 2025-09-11 1681/week @ 2025-09-18

7,188 downloads per month
Used in border-mlflow-tracking

WTFPL license

10KB
241 lines

Flatten serde Json

This crate flatten serde_json Object in a format similar to elastic search.

Examples

There is nothing to do

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

Flattens to:

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

Objects

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

Flattens to:

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

Array of objects

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

Flattens to:

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

Array of objects with normal value in the array

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

Flattens to:

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

Array of objects of array of objects of ...

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

Flattens to:

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

Collision between a generated field name and an already existing field

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

Flattens to:

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

Dependencies

~0.4–0.9MB
~18K SLoC